Prevent componentDidMount from fetching data if already available from server-side
问题 ComponentDidMount() is triggered when the component is mounted, including when it is hydrated following server-side rendering. One of the solutions I found online is checking whether we have data in the state; however this requires a lot of code to include on every component. What are other solutions? componentDidMount() { // if rendered initially, we already have data from the server // but when navigated to in the client, we need to fetch if (!this.state.data) { this.constructor.fetchData