My guess is that, handleClick's first this.setState sets the loading property, which is not properly recognized as this.setState is an asynchronous operation.
You'd fetch after loading property is turned off if you want such a synchronous behavior.
Hey, I got the same problem with you. If you use HashRouter and click on its siblings, React only changes params in your Class Work, so componentDidMount will not be called again => webpage is not updated! You can add componentDidUpdate to fix this, or put this.handleClick() directly in Render() ( because React will invoke this as you click on another product).
it didn't work.
There is some styledComponent code that i remove
Here is my code:
Hi @iamkael .
Call
fetch
as a callback ofthis.setState()
.My guess is that,
handleClick
's firstthis.setState
sets theloading
property, which is not properly recognized asthis.setState
is an asynchronous operation.You'd fetch after loading property is turned off if you want such a synchronous behavior.
Hey, I got the same problem with you. If you use HashRouter and click on its siblings, React only changes params in your Class Work, so componentDidMount will not be called again => webpage is not updated! You can add componentDidUpdate to fix this, or put this.handleClick() directly in Render() ( because React will invoke this as you click on another product).
There is another solution with passing location property to your component.
You can check it here here