Comments (4)
Hmm. At the start of the function, the draft object should represent the latest state, so you should be able to just use that as a starting point for any comparisons.
I guess I'm not really seeing what the issue is here. Can you give a specific example, preferably with a CodeSandbox repro, of something you want to do that isn't working correctly?
from redux-toolkit.
Sure,
import { createReducer } from "redux-starter-kit";
export const initialState = {
result: []
};
const Notifications = createReducer(initialState, {
TEST(state, action) {
console.log(state.result);
}
});
Notifications(undefined, { type: "TEST" });
In the above example I'd expect the log to be []
but it is instead a Proxy object. I'm presuming this is because the draft
object is passed as the 'state' and the actual state object is inaccessible. So I can write to the state, but I cannot read from it. Or have I misunderstood?
A use case for this might be wanting to compare a value on the existing state object before deciding what to update on the draft
Link - https://codesandbox.io/s/2v017oozy0 (needs browser console)
It looks like Immer supports passing an object as the third argument to pre-populate the draft
. Perhaps that would solve the issue?
from redux-toolkit.
Immer is using a Proxy to wrap the state object, but as far as I know it should still let you access the underlying state as normal if you need to read values.
If I do console.log(state.result.length)
in that sandbox, I see it print 3, as expected.
from redux-toolkit.
Ah, okay. I think that even though I'm not seeing []
I can still access things like .map()
and .length
.
Thanks for your time!
from redux-toolkit.
Related Issues (20)
- How to use `TypedUseQuery` as a signature of a method? HOT 5
- unexpected behaviour of dispatching action in redux HOT 11
- [Breaking] Rename RTKQ `RootState` type HOT 2
- Broken Typescript Definition Exports with latest minor update HOT 5
- Do not cancel retry requests on route change HOT 2
- `refetchOnFocus`: Unintended refetch when iframe exists in the page HOT 3
- Slow typescript intellisense caused by createSlice HOT 7
- typescript errors after 2.2.6 to 2.2.7 update HOT 9
- Best pattern for reused `selectFromResult`? HOT 4
- Redux Toolkit not compatible with React 19? Could not resolve dependency. HOT 3
- Problems trying to migrate to toolkit HOT 2
- Exporting a default response handler for fetchBaseQuery HOT 1
- Extract all Parameters type HOT 7
- Typescript error with providesTags HOT 4
- Ability to configure createAsyncThunk for a custom serializeError
- Circular Dependencies in my React Project after following documentation HOT 4
- Previously accessible types are no longer accessible from 2.2.6 -> 2.2.7 HOT 3
- UseQuery can't be imported anymore HOT 3
- Destructuring reducer action parameter => Wrongly ActionCreatorWithOptionalPayload while strict is set to true HOT 2
- Change query arguments while polling on an endpoint
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 redux-toolkit.