-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
PayloadAction with meta does not work #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The default behaviour of RTK is to create an action creator with only one argument and only a payload property. This behaviour cannot be modified by TS annotations, because TS annotations have no effect on runtime behaviour. You can use the In your specific case, you'd want something along the lines of const cakeSlice = createSlice({
name: 'cake',
initialState,
reducers: {
fetchAll: {
reducer(
state,
action: PayloadAction<Cake[], string, { currentPage: number }>
) {
state.all = action.payload
state.meta = action.meta
},
prepare(payload: Cake[], currentPage: number) {
return { payload, meta: { currentPage } }
}
}
}
}) PRs to make this more clear in the docs are always welcome! |
My tsconfig {
"compilerOptions": {
"resolveJsonModule": true,
"target": "esnext",
"module": "commonjs",
"lib": [
"es6"
],
"allowJs": true,
"jsx": "react-native",
"noEmit": true,
"incremental": true,
"isolatedModules": true,
"strict": true,
"moduleResolution": "node",
"baseUrl": "./src",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
},
"exclude": [
"node_modules",
"babel.config.js",
"metro.config.js",
"jest.config.js"
]
} |
Unfortunately, there's nothing wrong with that as well. Could you try to reproduce the problem in a codesandbox? Without something we can both access, it's just guesswork :/ |
@phryneas #350 and this comment fixed the problem. Thanks for your time! |
Please make sure to report accurate version information in the future. |
v1.3.0-alpha.8
Please check my example here
The text was updated successfully, but these errors were encountered: