xxxxxxxxxx
If you are installing redux in an existing react project,
please be sure alter the index.js file to include the provider and
store from the redux module and app folder respectively.
xxxxxxxxxx
// store.js
import { configureStore } from '@reduxjs/toolkit'
export const store = configureStore({
reducer: {},
})
// index.js
import { store } from './app/store'
import { Provider } from 'react-redux'
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
)
xxxxxxxxxx
// Redux + Plain JS template
npx create-react-app my-app --template redux
// Redux + TypeScript template
npx create-react-app my-app --template redux-typescript
xxxxxxxxxx
import { apiSlice } from '../api/apiSlice'
export const apiSliceWithUsers = apiSlice.injectEndpoints({
endpoints: builder => ({
getUsers: builder.query({
query: () => '/users'
})
}),
overrideExisting: false,
})
export const { useGetUsersQuery } = apiSliceWithUsers
xxxxxxxxxx
createAction('tagsLoadSuccess', (tags: string[]) => {
return {
payload: tags,
};
})