Skip to content Skip to sidebar Skip to footer

Why A Child Component's State Keeps Clearing?

I have multiple layers of React components for getting an embed from a music service API, including a higher-order component that hits the API to populate the embed. My problem is

Solution 1:

The problem is that const WithAPIEmbed = withAPI( Embed ); is inside the render method. This creates a fresh WithAPIEmbed object on each render, which will be remounted, clearing any state below. Lifting it out of the class definition makes it stable and fixes the problem.


Post a Comment for "Why A Child Component's State Keeps Clearing?"