Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/pavlelekic/update-if-props-change

A handy React.js component to prevent re-rendering of sections of larger components that do not need to be re-rendered.
https://github.com/pavlelekic/update-if-props-change

javascript react react-native reactjs

Last synced: about 1 month ago
JSON representation

A handy React.js component to prevent re-rendering of sections of larger components that do not need to be re-rendered.

Awesome Lists containing this project

README

        

## Do you absolutely need this?

You don’t. You can achieve the same functionality with a lot more typing. What this component does is it prevents rerendering of it’s child components unless some of the variables that they depend on change.

So you could extract those child components into a separate component, implement a `shouldComponentUpdate()` method and you would have the same functionality. With much more typing.

## Instalation

Via npm:

`npm install update-if-props-change --save`

## How to use it
This component is especially useful if you have a big component with few sections that depend on different props/state variables.

Since all those sections belong to the same component, they will be rerendered whenever any of the props/state variables change. You don’t want that. You want the section of a big component to be re rendered only when variables that that section depends on change.

You can setup this ‘conditional’ re-rendering easy inline with `` component. Here is an example:
```javascript

render() {
return (



{this.props.someVar1 + this.state.someVar2}




{this.props.someVar3}



);
}
```

### Props

`props` - Array of variables that you want to watch for changes. They can be state variables, props, whatever. Whenever any of those variables change, the child components of `` will be rerendered.