state and props. Example. — This is fundamentally different that how class-based components work. — Example with a functional component. — Example with a class-based component. — Example of a functional component mimicking the behavior of a class-based component.
This is overly simplistic. Do *not* use this in production. let [value, setValue] = useState(() => { let value = localStorage.getItem(key); if (value) value = JSON.parse(value); return value || defaultValue; }); const setValueAndStore = val => { localStorage.setItem(key, JSON.stringify(val)); setValue(val); }; return [value, setValueAndStore]; };
storing ephemeral state. — Whether or not a list is sorted ascending or descending. — Current contents for a search filter. — The currently selected module in the Design Editor or Studio. Here is a demonstration.