#between components

11 messages · Page 1 of 1 (latest)

plush fulcrum
#

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} />  <PodcastNumber />

79 | <Episode podcast_id={podcasts[0]["_id"]} episode_number={1} />
| ^
80 | </p>
81 |
82 | </>`

#

this compiles but gets that runtime error

#

it works without 79

swift night
#

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>
    )}
plush fulcrum
#

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()

#

@azure sage to make updates between components, if I am not using a mutation, should I - useState();

azure sage
#

@plush fulcrum 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.

plush fulcrum
#

Got it, wasn’t sure if convex had some different magic