I have a parent component, that render one child component several time. This child component is used in many different components. I need to have an array in this child component that keeps all the previous renders of the component, then get access to the largest text passed to it.
import TextComponent from '../../text'
const ParentComponent = ()=>{
// ... some code here and get some data from API
const text = getTextFromAPI()
return (
<>
<ARandomComponent/>
<AnotherRandomComponent/>
<TextComponent text={text}/>
</>)
}
In the TextComponent
I need to know what text each element received, and return the largest text. I thought maybe I can have an array inside TextComponent
but of course with each render, component has fresh data and I know this is by design.
Is there any way to active this? To store a value in the TextComponent
that other renders from different places still have access to that value