4 ms·
I'm skeptical about the way state can change from under you within the same execution of the rendering function. This type of mutability will prevent all the he
by ht85 6y ago
I'm skeptical about the way state can change from under you within the same execution of the rendering function. This type of mutability will prevent all the help that typescript normally gives for complex components.
Also if anyone has used it, do you have to use this pattern if you have derived state?
setState({
displayName: `${state.user.firstName} ${state.user.lastName}`
})
If you simply do `const displayName = ...` in the component, will the component update properly?
- ryansolid 6y agoFeel free to shoot any issues or discussions on our gitter or reddit. You are correct because it doesn't work like that. It works more like MobX. There is no render function that runs repeatedly. Instead everything is split apart granularity and only those pieces update. If you want to have derived state. Simply wrap it in a function or use it in a JSX binding. Ex. const displayName = () => `${state.user.firstName} ${state.user.lastName}` return <span>{displayName()}</span>; or: return <span>{`${state.user.firstName} ${state.user.lastName}`}</span>; or: // this expensive to calculate: const displayName = createMemo(() => `${state.user.firstName} ${state.user.lastName}`) return <span>{displayName()}</span>;