Comments (5)
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.
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.
Lines 121 to 123 in 4d0b416
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.
proposed a fix in the code here #40
from reinspect.
Had the same issue when passing null as the initializer. Passing undefined solves this.
from reinspect.
Related Issues (20)
- Crashes when Redux Devtools Chrome extension is not installed HOT 3
- Discussion: Make id parameter optional HOT 2
- how to get dispatch when not use useReducer (e.g. component was unmount) HOT 2
- Crash with useState when setState(null) HOT 2
- store shared between useState HOT 1
- Babel transform plugin that automagically rewrites code to enable/inject reinspect
- package.json "types:" missing
- Make compatible with react-use middleware. HOT 2
- Live demo is broken HOT 2
- '/' in id does not work
- Would it be possible to auto-assign ids (and use that as the default)?
- Can you expose the context so that we can access the global store?
- Disable reduxDev tools for production HOT 2
- dispatching reducer actions from devtools not working
- Can this be used when using use-immer?
- If StateInspector is in React.StrictMode no output to redux devtools
- Typescript Props Type Definition for StateInspector is incompatible with `children` prop HOT 2
- Anyway to avoid losing normal redux logs? HOT 1
- Is there anyway to get the "trace" tab working in Redux Dev tools
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reinspect.