All you need to know about the Zustand API

Introduction

Let’s first discuss why you should use a state management library in the first place.

Importance of state management

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

React State Management With Zustand
3.10 GEEK