Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
20 replies
jakeman

Why does react rerender this at the component level but not when using a hook?

I've been toying with a type-writer effect in react and cant understand why react's lifecycle is working this way.

Can someone explain why react is re-rendering the <WithoutHook/> component such that it doesnt work
While the <WithHook/> one does?

https://codesandbox.io/s/damp-moon-v24dzf?file=/src/App.jsx

Notice 'strict mode' is on and if you disable it, it still breaks when not using a hook.
CodeSandbox
damp-moon-v24dzf using react, react-dom, react-scripts
damp-moon-v24dzf - CodeSandbox
Was this page helpful?