Elaborate on the documentation of preloadedState#2145
Elaborate on the documentation of preloadedState#2145dggsax wants to merge 2 commits intoreduxjs:masterfrom
Conversation
| } | ||
|
|
||
| // Not correct, we don't provide a value for `theme`. You would get the following typescript error if you tried to assign preloadedState the `PreloadedState<RootState>` type: Property 'theme' is missing in type '{ showNavigationPanel: false; }' but required in type '{ theme: "Dark" | "Light"; showNavigationPanel: boolean; }'. | ||
| const incorrectPreloadedState = { |
There was a problem hiding this comment.
@phryneas is there a way that I can give this the type PreloadedState<RootState> and have the type error be displayed in the documentation without breaking the compilation of the MDX?
|
✅ Deploy Preview for redux-starter-kit-docs ready! 🔨 Explore the source changes: 5f22b97 🔍 Inspect the deploy log: https://app.netlify.com/sites/redux-starter-kit-docs/deploys/6235122abb1a3c000851cabe 😎 Browse the preview: https://deploy-preview-2145--redux-starter-kit-docs.netlify.app |
|
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 36342d9:
|
|
✅ Deploy Preview for redux-starter-kit-docs ready! 🔨 Explore the source changes: 36342d9 🔍 Inspect the deploy log: https://app.netlify.com/sites/redux-starter-kit-docs/deploys/623512d412d4cf0008fba3c0 😎 Browse the preview: https://deploy-preview-2145--redux-starter-kit-docs.netlify.app |
|
Publishing this PR to start getting some feedback on what I've written here. Here's the direct link to preview the changes that I've made in this PR: https://deploy-preview-2145--redux-starter-kit-docs.netlify.app/api/configureStore#preloadedstate |
| appState: AppState | ||
| } | ||
|
|
||
| // Not correct, we don't provide a value for `theme`. You would get the following typescript error if you tried to assign preloadedState the `PreloadedState<RootState>` type: Property 'theme' is missing in type '{ showNavigationPanel: false; }' but required in type '{ theme: "Dark" | "Light"; showNavigationPanel: boolean; }'. |
There was a problem hiding this comment.
✋ This line should be broken into multiple separate // comments, so that there's no horizontal scrolling needed
|
|
||
| > **Note**: `preloadedState` is not recursively partial! For each part of your application's initial state that you decide to provide initial values for, you must define values for **all** properties of that part of state. They will be passed to your reducers as the initial state, and they themselves can't be partial. | ||
|
|
||
| Let's discuss the above point some more and provide a few tips for how you fully leverage `preloadedState` in your application and tests. For example, let's stay we start with the following initial state: |
There was a problem hiding this comment.
✋ The info from here on down is useful, but I don't think it needs to be part of the main flow of the page.
Over in the Redux core docs, we have a <DetailedExplanation> component that toggles display of content, as soon at https://redux.js.org/style-guide/#structure-files-as-feature-folders-with-single-file-logic and other spots.
We don't have that component in this repo, but it should be straightforward to copy-paste it over and wrap that around all the content after the "Note" block.
There was a problem hiding this comment.
Perfect! I'll look into adding that. Thank you
In the Reactiflux discord, I asked the following question:
To which @markerikson replied "Your slice reducers will be given the pieces of state you provide at startup. Those can't be partial themselves.". Which is a pretty obvious answer if you think about it.
With this PR, I hope to provide some elaboration on
preloadedStatein the documentation so that others who come to this conceptual question can achieve the same understanding. This is my first attempt at contributing to the RTK documentation, so please let me know if you have any feedback on how I can make the explanations/examples more concise.