GithubHelp home page GithubHelp logo

Comments (5)

budavariam avatar budavariam commented on July 23, 2024 1

I ran into this issue as well, when I passed a function, an object and a string as the third parameter.
For a quick fix I passed a function that only returns its parameter as the third param, and added id as the fourth.

useReducer(reducerFn, initialValue, (a)=>a, "myUniqueID")

My Idea of what is happening

I inspected the code with 3 parameters, reducer, initialState and a string ID.
I figured that this part assumes that the initializer is defined, and if it exists then it calls it as a function.

When we do not call it with a lazy init function as a third parameter, the initializer's default value will still be the reinspect.useReducer's 3rd param, but it is not a function, it is only a string.

I think this if branch knows that there is no initializer function (since the first param is a string), but it does not indicate this knowledge in any way, and the initializer stays the first param (the string ID), which is not going to be falsy (unless it is an empty string ofc), so it will be called as a function, and this error will occur.

So as a quick fix I passed a function that only returns its parameter as the third param, and added id as the fourth.

from reinspect.

antoniojps avatar antoniojps commented on July 23, 2024

Same here, I'm trying to understand what the initializer is, but from reading the docs I don't understand. What is the initializer?

The documentation is lacking an useReducer code example.

from reinspect.

Singha360 avatar Singha360 commented on July 23, 2024

@budavariam

reinspect/src/useReducer.ts

Lines 121 to 123 in 4d0b416

return store && id
? useHookedReducer(reducer, initializedState, store, id)
: useReactReducer(reducer, initialState, initializer)

Pretty sure that initializer should instead be id on line 123.

Nevermind, didn't completely read through the useReducer function (reinspect version). Also instead of the workaround you proposed, you can also pass in undefined as the third parameter and then followed by the id as the fourth parameter.

Seems like this is the intended behavior though, because in the official docs for hooks, they do mention the lazy initialization that can be passed in as the third parameter for useReducer function from React as you mentioned.

So I suppose this issue can be closed? @BobLamarley

ADDITIONAL INFO: This info is mentioned on the bottom of the repo's readme...

from reinspect.

flamerohr avatar flamerohr commented on July 23, 2024

proposed a fix in the code here #40

from reinspect.

discobean avatar discobean commented on July 23, 2024

Had the same issue when passing null as the initializer. Passing undefined solves this.

from reinspect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.