nandorojo / solito

🧍‍♂️ React Native + Next.js, unified.
https://solito.dev
MIT License
3.54k stars 181 forks source link

useParam always returns the same value (the first selected) #75

Closed rodbs closed 2 years ago

rodbs commented 2 years ago

I've got a blog/[slug].js structure

In react navigation I have

 <NavigationContainer
        linking={useMemo(
          () => ({
            prefixes: [Linking.createURL('/')],
            config: {
              initialRouteName: 'home',
              screens: {
                HomeScreen: '',
                BlogScreen: 'blog',
                BlogSlugScreen: 'blog/:slug',
                CourseSlugScreen: ':courseSlug/:categorySlug/:slug',
...

In the Blog screen I have:

import { createParam } from 'solito'
const { useParam } = createParam() 

export function BlogSlugScreen({   route }) {
  const [slug] = useParam('slug')
   console.log('slug', slug)
   console.log('route', route)
   ...

So, first time a select a post, slug keeps the right value and same thing for route.params.slug. But next times, route.params.slug stores the right value while slug keeps storing the first selected (it's not updated). Is it a bug ?

nandorojo commented 2 years ago

i believe this is a duplicate of #51

nandorojo commented 2 years ago

if you use setSlug it would work for now, as shown in the docs

nandorojo commented 2 years ago

but yeah i need to fix this

rodbs commented 2 years ago

setSlug ? where is that in the docs?

rodbs commented 2 years ago

you mean create an state variable and store route.params.slug? setSlug(route.params.slug)

nandorojo commented 2 years ago

I mean use the setter from the useParam docs:

const [slug, setSlug] = useParam('slug')

// and then...

setSlug('123')

But this will be fixed when I have time.

nandorojo commented 2 years ago

What I mean is, if you update slug via that setSlug function, it'll work for now.

rodbs commented 2 years ago

ok , I understand. Thx!!

nandorojo commented 2 years ago

closing as duplicate of #51