I'm using withState to manage the value of a controlled input. Here's how i'm using it:
import { compose, withState, mapProps } from 'recompose';
const MyComponent = ({
originalTitle,
inputOnChange,
title
}) => {
return (
<div>
<input type="text" value={ title } onChange={ inputOnChange }/>
</div>
);
};
export default compose(
withState('title', 'changeTitle', (props) => props.originalTitle),
mapProps((props) => _.assign(props, {
inputOnChange: (e) => props.changeTitle(() => e.target.value)
}))
)(MyComponent);
And the error i'm getting is:
Warning: This synthetic event is reused for performance reasons. If you're seeing this, you're accessing the property `target` on a released/nullified synthetic event. This is set to null. If you must keep the original synthetic event around, use event.persist(). See https://fb.me/react-event-pooling for more information.
Uncaught TypeError: Cannot read property 'value' of null
Now, I read about Event Pooling, and saw some recommendations to use event.persist(), but I couldn't figure out how to use it in this setup.
Any help will be greatly appreciated!
Thanks
Ok, so the answer was so simple it's embarrassing, but i'll just post it here and maybe it could help someone else..
mapProps((props) => _.assign(props, {
inputOnChange: (e) => {
e.persist();
props.changeTitle(() => e.target.value);
}
}))
Or just
mapProps((props) => _.assign(props, {
inputOnChange: (e) =>
props.changeTitle(e.target.value);
}))
You can use a simple value in changeTitle
Great! that works too. thanks
i don;t konow
Most helpful comment
Or just
You can use a simple value in
changeTitle