Skip to content
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

docs: root state type with TypeScript and configureStore #326

Merged
merged 5 commits into from
Oct 23, 2021

Conversation

firstred
Copy link
Contributor

@firstred firstred commented Jan 21, 2020

When passing the root reducers directly to configureStore(), it is not possible to get the root state type directly from the reducers. For the type, you will then have to access store.getState() instead.

So, instead of type RootState = ReturnType<typeof rootReducer> you will have to use type RootState = ReturnType<typeof store.getState>. This PR adds this little piece of information.

@netlify
Copy link

netlify bot commented Jan 21, 2020

Deploy preview for redux-starter-kit-docs ready!

Built with commit 1334799

https://deploy-preview-326--redux-starter-kit-docs.netlify.com

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 21, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit ea5396c:

Sandbox Source
modest-cache-um90l Configuration
nostalgic-johnson-mkpki Configuration
rsk-github-issues-example Configuration

@markerikson
Copy link
Collaborator

The info is just a bit off. The problem comes when you don't define the root reducer explicitly, and instead pass the slice reducers to configureStore(), like:

const store = configureStore({
    reducer: {
        first: firstReducer,
        second: secondReducer,
    }

});

There's no rootReducer to reference, so we have to refer to store.getState instead.

Can you tweak the wording and example to match that?

@firstred
Copy link
Contributor Author

I am going to familiarize myself a bit more with the material before I continue with this PR. I thought I knew a lot about the Redux Starter Kit / Toolkit already, but today showed that it still had a few surprises for me.
Thank you for being so patient and helpful. It's much appreciated!!

@markerikson
Copy link
Collaborator

Sure, and thanks for putting the PR together!

@firstred
Copy link
Contributor Author

I just updated the PR, taking this feedback into account:

@markerikson
Copy link
Collaborator

This PR needs to be updated to take into account the changes from #549 and #559 .

Co-authored-by: Lenz Weber <mail@lenzw.de>
@markerikson markerikson merged commit 412727a into reduxjs:master Oct 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Describe inferring RootState type from store.getState
3 participants