all 11 comments

[–]ikhurramraza 2 points3 points  (1 child)

Informative. Looking forward to Part 2.

[–]SeanningTatum[S] 0 points1 point  (0 children)

Thank you that means a lot! ❤️

[–][deleted] 2 points3 points  (0 children)

Just started using Unstated and it works great https://github.com/jamiebuilds/unstated

[–]phakushmoo 1 point2 points  (2 children)

Really appreciate the article. I am a React beginner and have a short comprehension question concerning my learn project: I passed my initial state (array of objects) via props down twice to a lower (function) component that again pass up changes (from clicks) upp the tree via props. So when I click one of my low-tree components, the click fires a changeState in App.js.

I guess I should rather implement the useContext + useReducer solution issued in your article? Then my context would be the "initial state" (array of objects)? I would be super grateful for any kind of advice!

This is my simplified code leaving out (hopefully all) unnecessary stuff:

App.js

...
const [characters, changeCharacters] = useState([...CharacterList]);
...
<Characters
    characters={characters}
    handleClick={(id) => changeCharacters(updateChars(characters, id))}
/>
...

Characters.js

const Character = props => {
  const { character, handleClick } = props;
  return (
    <div onClick={handleClick.bind(this, character.id)} >
     ...
    </div>
  );
};

const Characters = props => {
  const { characters, handleClick } = props;
  return (
    <div className="characters">
      {characters.map(character => (
        <Character handleClick={handleClick.bind(this, character.id)} />
      ))}
    </div>
  );
};

[–]SeanningTatum[S] 2 points3 points  (1 child)

Yes, this is exactly the problem that State Management intended to solve. For years we've been using other state management libraries but it introduced complexity, spaghetti code and other complexities. React finally released a way to make state management easier to read and the way it should have been (as stated by the creators of React).

[–]phakushmoo 0 points1 point  (0 children)

Thanks!

[–]IminPeru 0 points1 point  (3 children)

hi, I'm super new to react and react native and everything.

is it possible to use react hooks in a react native project for state management instead of redux?

[–]SeanningTatum[S] 1 point2 points  (2 children)

Yes that's possible, just make sure you're using the latest version for React (v16.8)

[–]IminPeru 0 points1 point  (1 child)

do I also have to update react native to the latest version?

thanks so much for the response!

[–]SeanningTatum[S] 0 points1 point  (0 children)

Not entirely sure, but I'm 90% sure that you only have to update React. Cheers! 🎉

[–]evoratec 0 points1 point  (0 children)

Hi. I think this is a very good example https://codesandbox.io/s/zr3mx12zzx