import { configureStore } from '@reduxjs/toolkit';
import { pokemonApi } from './pokemonApi';
import authReducer from './authSlice';
export const store = configureStore({
reducer: {
[pokemonApi.reducerPath]: pokemonApi.reducer,
auth: authReducer, // Dodajemy authReducer
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware().concat(pokemonApi.middleware),
});
W tym przykładzie, authReducer jest dodany do reducer z kluczem auth. Teraz możesz używać authReducer w swoim kodzie.
Wyjaśnienie
reducer to obiekt, który zawiera wszystkie reducery, które chcesz użyć w swoim Redux Store.
[pokemonApi.reducerPath]: pokemonApi.reducer dodaje reducer API do Store.
auth: authReducer dodaje authReducer do Store z kluczem auth.
Dostęp do stanu
Teraz możesz uzyskać dostęp do stanu auth w swoim kodzie, używając useSelector z react-redux:
javascript
import { useSelector } from 'react-redux';
function YourComponent() {
const authState = useSelector((state) => state.auth);
// ...
}
Dispatching akcji
Możesz również dispatchować akcje do authReducer, używając useDispatch z react-redux:
javascript
import { useDispatch } from 'react-redux';
import { someAction } from './authSlice';
function YourComponent() {
const dispatch = useDispatch();
dispatch(someAction());
// ...
}
Pamiętaj, że someAction powinno być akcją zdefiniowaną w authSlice.
User
Objects are not valid as a React child (found: object with keys {status, data}). If you meant to render a collection of children, use an array instead.
Takie cos mam jak nic nie wpisze jak sie loguje i klikne przycisk login
Tak to wyglada w kodzie
Assistant
Ten błąd oznacza, że próbujesz renderować obiekt jako dziecko w React. W Twoim przypadku, błąd jest spowodowany przez linię kodu, która renderuje błąd: