React Hooks

Since moving teams and re-learning Angular I’ve had the chance to work recently on a rather nice ReactJS project. It gave me my first real exposure to full stack development and I have to say, whilst terrified, I felt well chuffed when it was all done – with help of a couple of amazing colleagues.

The really sweet part was using React Hooks for the first time. Rather than wrestling with state and setState it was just a simple useEffect and useState which was a revelation. So nice.

Never felt entirely comfortable mixing mark-up and functions, that was a bit of a hurdle to overcome. Then the whole state and setState really grinds my gears too.

   .then(response => response.json())
   .then(data => this.setState({data}));

Instead it’s a nice simple case of creating a fetch.js service file for carrying out the api calls. Then a really clean and simple few lines to set up the object for using on the page.

 const [data, setData] = useState(null);
 useEffect( () => {
 }, []);

I personally find this a lot cleaner and nicer to work with. A plus side is also the test-ability of it, which matters to me as it’s a key part of my employers ethos.