How to rerender component with recompose, when prop is changed from outside the view component?
const Message = ({msg}) => <div>The prop has a value of <b>{msg}</b>.</div>
const App = Recompose.withProps(() => {
let msg = 'One'
// this async update doesn't work because nothing triggers a rerender
setTimeout(() => {msg = 'Two'}, 500)
return {msg}
})(Message)
ReactDOM.render(<App/>, document.getElementById('app'))
When this component is rendered, it shows value as One but doesn't change to Two after 500ms even though it changes the prop.
The setTimeout
here simplifies the case when in the actual usecase I subscribe to websocket server and when a message is pushed, the Message component gets updated.