Must be some fundamental wrong-headedness with my understanding. I have a react native app that is supposed to display multiple modal popups which I have implemented as a stack of render functions.
render() {
if (this.state.popupStack.length > 0) {
return this.state.popupStack[0]()
} else {
return null
}
}
For instance to display something on the stack, I do this:
this.state.popupStack.push( () => <SomeComponent thing={propA} /> )
this.state.popupStack.push( () => <SomeComponent thing={propB} /> )
And it works fine, I can push all sorts of things onto the stack and shift them out and the next thing renders.
The issue occurs if the components (not functional elements) need state which I initialize in their constructors. The first time I use SomeComponent in this way, the constructor is called and all is good. But if I push the same component again, the component is rendered according to the changed props, but the constructor isn't called. React figures the component is mounted and is happy to pass new props in, but it messes things up because it is using the previous components state. The 2nd render function pushed on the stack is using the same instance of SomeComponent. I dont want that.
Does this makes sense?
I figured it would call the constructor every time...
What's my malfunction :)
Thanks very much