Good afternoon,
I have a react native project. I currently have 3 major UI components:
A timeline which consists of a user defined number of channels, which have a fluctuating number of events (Think gantt chart or audio editors). I want a button defined in the timeline to call a function defined in the child channel object, change some parameters as defined in the child function, and re-render.
UPDATED: I refactored the original code posted here to all be contained within a single class, but having similar issues. Refactored code:
class TIMELINE extends Component{
constructor(props) {
super(props);
this.state = {
allEvents: [],
allChannels:[],
};
}
render() {
return(
<View>
<Text style={styles.welcomeMessage}>Timeline</Text>
<View name=CONATINER_VIEW>
{
this.state.allChannels.map((channel)=>{
console.log(channel); //<<<<This is Printing proper info
renderChannel(this, channel) //<<<< Renders nothing
})
}
</View>
</View>
);
}
renderChannel = (timeline, channel) =>{
return (
<View style={[styles.container, styles.channelContainer, styles.channelWrapper]} name="ChannelWrapperViewThing">
<View style={styles.verticleLine}></View>
<Pressable style={styles.eventLane} onPressIn={timeline.handlePressIn} onPressOut={timeline.handlePressOut}>
{//RenderEvents TBD}
</Pressable>
</View>
)
}
This refactored code splits out the recursive display of channels and events into their own rendering functions. During the loop, I print out the stored channel datils to the console, and that print is working and printing the expected values, but nothing returned from renderChannel() is rendered, and if I inspect the wrapping view name=CONATINER_VIEW, has the correct number of children (depending on how many channels have been added) in the array, but they are all undefined. Also puzzling, if I write a temporary function renderEvents and just have it print to console, it will for each channel object and will print data passed to it properly, but still nothing renders.
Any suggestions?
Thank you!
2
Answers
The way I trigger a function in the child from the parent is using useEffect
You need to return the value of
renderChannel
inside themap
, otherwise everything would be undefined: