diff --git a/docs/api/createEntityAdapter.mdx b/docs/api/createEntityAdapter.mdx index be14acc886..d08d145bc9 100644 --- a/docs/api/createEntityAdapter.mdx +++ b/docs/api/createEntityAdapter.mdx @@ -274,6 +274,39 @@ const booksSlice = createSlice({ }) ``` +You can also pass in an array of entities or a `Record` object to pre-populate the initial state with some entities: + +```js +const booksSlice = createSlice({ + name: 'books', + initialState: booksAdapter.getInitialState( + { + loading: 'idle', + }, + [ + { id: 'a', title: 'First' }, + { id: 'b', title: 'Second' }, + ], + ), + reducers: {}, +}) +``` + +This is equivalent to calling: + +```js +const initialState = booksAdapter.getInitialState({ + loading: 'idle', +}) + +const prePopulatedState = booksAdapter.setAll(initialState, [ + { id: 'a', title: 'First' }, + { id: 'b', title: 'Second' }, +]) +``` + +The first parameter can be `undefined` if no additional properties are needed. + ### Selector Functions The entity adapter will contain a `getSelectors()` function that returns a set of selectors that know how to read the contents of an entity state object: