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
TextComponent? In such case, store the array as state in the parent component.TextComponentis getting used in 15 different parent components, I don't want to duplicate the logic in each parent component, and that's why I was looking for a way to implement it inside theTextComponent@zhulienTextComponentis getting rendered in 15 different places, and I don't want to place the logic in the parent components. But I need theTextComponentitself keep track of its other instancesTextComponents from there.