Quote:
Originally Posted by microbet
Thanks. This fixed the problem.
I imagine when imageId becomes set when the fetch returns, react re-evaluates and re-renders "<Answers..>"?
Quote:
Originally Posted by microbet
One of the things I googled was "force rerender react" or some such, but didn't find anything that worked. There is something called "hooks" that I hear about on react podcasts, but podcasters say it's brand new and they aren't necessarily using it for production yet.
I think hooks are just designed to allow you to use state and some other react features without using a class.
There was always talk of stateless-functional-components getting optimized some point in the future to not be considered the same as react classes by react internally, I imagine hooks are a similar optimization.
Quote:
Originally Posted by suzzer99
Force rerender (and really anything with force in it) sounds like one of those things that if you have to use it, you probably aren't doing something right.
Quote:
Originally Posted by microbet
Prolly, but react should probably rerender automatically when the value of the props it takes changes.
There is a method in react to force a rerender, but like suzzer says it is gross and you shouldnt use it. At my last company large parts of our codebase used force rendering because the dev couldnt be bothered to figure out why the render cycle was not behaving as intended.
You can also use a PureComponent and the method shouldComponentUpdate if you are doing something that wont rerender accurately.
However, usually stuff like this is your <Answer/> component using componentWillMount or another lifecycle method that doesn't care about prop changes and just renders once.