1.0.1 • Published 5 years ago

react-einfach v1.0.1

Weekly downloads
2
License
Apache-2.0
Repository
-
Last release
5 years ago

react-einfach

Write high performance React code for beginners

As you know, that there are quite a lot of pitfalls in React, unless you have much expertise. For instance, to avoid unnecessary re-render operations, to write component with shorter code.

This library aims to make sure even shitty code does not matter.

Set state with dirty check

React v16.8 introduced Hooks. It helps to write a much shorter variant of React.Component with functional components. However, in some case, you might set state with a object copy, but it triggers re-rendering of child (none pure) component.

The helper function withDirtyCheck give you a no-brain option to avoid this from happening!

Example:

const [formObject, setFormObject] = React.useState({name: '', email: ''})
setFormObject({...formObject, name: ''}) // will update state object

const [formObject2, setFormObjectIfDirty] = withDirtyCheck(React.useState({name: '', email: ''}))
setFormObjectIfDirty({...formObject, name: ''}) // will NOT update state object