Next.js Discord

Discord Forum

Why do I get the following error ?

Unanswered
European imported fire ant posted this in #help-forum
Open in Discord
Avatar
European imported fire antOP
"use client"
function Navbar() {
    const [providers, setProviders] = useState(null)
    const isUserLoggedIn = true

    useEffect(() => {
        const setProviders = async () => {
            const response = await getProviders()
            setProviders(response)
        }
        setProviders()
    }, [])

    return (
      {providers && Object.values(providers).map((provider) => (
              <button 
                  type="button" 
                  key={provider.name}
                  onClick={() => {signIn(provider.id)}}
                  className="black_btn"
              >
                  Sign In
              </button>
       )
      }
    )
}

This is my navbar component that I would like to use state in. However for some reason I get 2 errorrs. One on the
setProviders(response)
line where it says that the setProviders functions takes 0 arguments but I have provided 1. And more inside the map function because it says provider is of type uknown

10 Replies

Avatar
Californian
Are you sure the response is not empty? console log and see
Avatar
European imported fire antOP
But its a syntax error
The linter says that I have passed 1 argument to the method when I should have passed 0
Avatar
Californian
Maybe because the response is empty?
Avatar
European imported fire antOP
empty as in what ? Even if the response is null its an argument and the syntax highlighting would not know that its empty. Besides, the error is that I have passed 1 argument when the function asks for 0, so I dont see how the response being empty is relevant
Avatar
American black bear
1. rename the setProviders function instede the useEfecct
2. in order to see the error in the maping it would be good to see how are the providers comming from getProviders
Avatar
Eric Burel
you have a name clash indeed reusing setProviders in the closure
Avatar
European imported fire antOP
I switched it to an unnamed async and that seems to have worked
thanks for the heads up