burnstony#1975
burnstony#197511mo ago

between components

how do I pass the selected _id from one component to another so far trying this <> <p>Welcome {viewer}!!!</p> <p> <SelectPodcast podcasts={podcasts} />&nbsp;&nbsp;<PodcastNumber /> <Episode podcast_id={podcasts[0]["_id"]} episode_number={1} /> </p> </> getting this error Unhandled Runtime Error TypeError: Cannot read properties of undefined (reading '_id') Source app/add_dates/add_dates.tsx (79:41) @ SignedInContent 77 | <p> 78 | <SelectPodcast podcasts={podcasts} />&nbsp;&nbsp;<PodcastNumber /> > 79 | <Episode podcast_id={podcasts[0]["_id"]} episode_number={1} /> | ^ 80 | </p> 81 | 82 | </>
5 Replies
burnstony#1975
burnstony#1975OP11mo ago
this compiles but gets that runtime error it works without 79
erquhart
erquhart11mo ago
You'll want to make sure podcasts[0] has a value before you render.
{Boolean(podcasts[0]) && (
<p>
<SelectPodcast podcasts={podcasts} />&nbsp;&nbsp;<PodcastNumber />
<Episode podcast_id={podcasts[0]["_id"]} episode_number={1} />
</p>
)}
{Boolean(podcasts[0]) && (
<p>
<SelectPodcast podcasts={podcasts} />&nbsp;&nbsp;<PodcastNumber />
<Episode podcast_id={podcasts[0]["_id"]} episode_number={1} />
</p>
)}
burnstony#1975
burnstony#1975OP11mo ago
cool thanks If I have a select in another component how do I update the value in this component I am not storing the selection in convex. so do I need to use useState() @ballingt to make updates between components, if I am not using a mutation, should I - useState();
ballingt
ballingt11mo ago
@burnstony#1975 can you say more about what you want? In React, forgetting Convex, yes to store state you should use useState(). You can pass the setter as a prop to child components so they can set state in a parent.
burnstony#1975
burnstony#1975OP11mo ago
Got it, wasn’t sure if convex had some different magic Thanks

Did you find this page helpful?