bookmarkd icon indicating copy to clipboard operation
bookmarkd copied to clipboard

Violations of the minimal state principle.

Open Jwhiles opened this issue 8 years ago • 0 comments

I recommend trying to construct your react apps in a way that has as little state as is possible. If you can calculate something based on props, or other pieces of state - then that thing should not be additional state.

To give an example of this - in the pageHeader component. You set a search value in state, and then based on this value, and the prop books you generate search results which are then also saved into the state.

I would suggest removing search results from the components state, and extracting the logic into a function like (searchTerm, books) => searchResults which you can call in the render method as and when you need it.

Jwhiles avatar May 11 '17 18:05 Jwhiles