Drejer Drejer - 1 year ago 151
React JSX Question

React functional/stateless pure component

I'm beginning to switch to functional/stateless components in React, like the one below.

I do however have a problem with react-chartjs-2 re-drawing my charts, even though the data for them didn't change. Before I switched to functional components, this was easily solved by using Reacts PureComponent.

Is there a way to make React use the PureComponent for a stateless function?

const ListGroup = props => {
const {title, width} = (props);

return (
<ul className={"grid"} style={{width}}>

Answer Source

You can use recompose and wrap the component with the pure or onlyUpdateForKeys higher order components:

import pure from 'recompose/pure';

const PureListGroup = pure(ListGroup);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download