Let’s first discuss why you should use a state management library in the first place.
To put it simply, developers need a state management system because of React’s infamous prop drilling problem. Let me explain it to you via a code example.
Take a look at the following snippet:
function RenderIcon({company}) {
return (
<>
{company === 'apple' ? <AppleIcon/> : <SamsungIcon/>}
</>
);
}
function App() {
return (
<div>
<RenderIcon company="apple"/>
</div>
)
}
All we are doing here is rendering an icon based on the company
prop. Fairly simple. Let’s try complicating things up a bit.
#javascript #nodejs #react #programming