3 ms·
What are the other options here then? Not trolling just wondering. If an app has state it has to be dealt with somewhere...
by tonetheman 5y ago
What are the other options here then? Not trolling just wondering. If an app has state it has to be dealt with somewhere...
- dsego 5y agohttps://github.com/eugenkiss/7guis-React-TypeScript-MobX/blob/master/src/app/guis/flight.tsx https://github.com/eugenkiss/7guis-React-TypeScript-MobX/blo...
- edflsafoiewq 5y agoYou can dispense with the whole intermediate state variable and just do everything directly function calcState() { // Return field disabled for one-way trips elems.return.disabled = isOneWay(); let allOk = true; // All enabled fields are valid? for (const f of [elems.departure, elems.return]) { const isInvalid = ( !f.disabled && isBadFormat(f.value) ); setInvalid(f, isInvalid); if (isInvalid) allOk = false; } // Return trip after departure trip? if (allOk && !isOneWay() && isEarlyReturn()) { allOk = false; } // Enable submit if everything is OK elems.submit.disabled = !allOk; } function setInvalid(elem, invalid) { elem.setAttribute(ARIA_INVALID, invalid); } This follows the problem description quite closely, eg. "The return textfield is enabled if the combobox’s value is return flight" is implemented by one line, and not spread across seven different enable/disable calls.