Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Using setStepNav to update app-header nav

default discord avatar
michelcodelast year
6

I have a custom collection list view and I noticed that the steps in the header don't update when navigating to the custom list view.


So I searched the code to do it manually and found

useStepNav

and the corresponding

setStepNav

function.



But when using it I get:

TypeError: setStepNav is not a function

My code in my client component:


  const { setStepNav } = useStepNav()

  React.useEffect(() => {
    const nav: StepNavItem[] = []

    nav.push({
      label: t('stepList:title'),
      url: '/steps',
    })

    setStepNav(nav)
  }, [setStepNav, t])

(my collection is also called 'steps' btw, sorry for the confusion)


Is this the wrong way to update the steps in the app-header?

  • default discord avatar
    zed0547last year

    I'm thinking that your custom List view might be outside of the provider that threads this through



    Are other hooks working here?



    useLocale, useTheme, etc...?

  • default discord avatar
    michelcodelast year

    useAuth is working



    How could it be outside of the provider though?


    This is how I reference the component:


        components: {
          views: {
            list: {
              Component: '@/collections/Steps/components/step-list/StepsListComponent#StepsListComponent',
            },
          },
        },
  • default discord avatar
    zed0547last year

    Well, it would be outside the provider if custom list views are rendered outside the provider.



    If useAuth is working though, then that's not the case



    Here's the root provider:

    https://github.com/payloadcms/payload/blob/main/packages/ui/src/providers/Root/index.tsx#L54

    Maybe try using

    SetStepNav

    component instead?



    In your view and pass it a list of { label: string, url: string }



    I'm not sure why it's giving you trouble here tbh

  • default discord avatar
    michelcodelast year

    I have no clue either, but using the

    SetStepNav

    component worked!


    Thanks!

  • default discord avatar
    zed0547last year
    Nice

    - glad it worked for ya! My pleasure

  • default discord avatar
    _niccolas__last year
    @654031862146007055

    This guy had a same problem as you see

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.