ADD: ajout des redux

stub-api
Alban GUILHOT 3 years ago
parent 5caa3895db
commit 06575e0ed3

@ -0,0 +1,12 @@
import React from 'react'
import App from './App'
import store from './src/redux/store'
import { Provider } from 'react-redux'
export default function Index(){
return(
<Provider store={store}>
<App />
</Provider>
)
}

File diff suppressed because it is too large Load Diff

@ -12,6 +12,7 @@
"@react-navigation/bottom-tabs": "^6.4.0", "@react-navigation/bottom-tabs": "^6.4.0",
"@react-navigation/native": "^6.0.13", "@react-navigation/native": "^6.0.13",
"@react-navigation/stack": "^6.3.2", "@react-navigation/stack": "^6.3.2",
"@reduxjs/toolkit": "^1.8.6",
"expo": "^46.0.15", "expo": "^46.0.15",
"expo-status-bar": "~1.4.0", "expo-status-bar": "~1.4.0",
"jest": "^26.6.3", "jest": "^26.6.3",
@ -21,7 +22,8 @@
"react-native": "^0.69.6", "react-native": "^0.69.6",
"react-native-gesture-handler": "~2.5.0", "react-native-gesture-handler": "~2.5.0",
"react-native-safe-area-context": "4.3.1", "react-native-safe-area-context": "4.3.1",
"react-native-web": "~0.18.7" "react-native-web": "~0.18.7",
"react-redux": "^8.0.4"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.12.9", "@babel/core": "^7.12.9",

@ -0,0 +1,24 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit"
import { User } from "../../core/user";
interface currentUserState {
value: User[]
}
const initialState: currentUserState = {
value: [],
}
export const currentUserSlice = createSlice({
name: "currentUser",
initialState,
reducers: {
loginUser: (state, action: PayloadAction<User>) => {
state.value.push(action.payload);
},
},
});
export const { loginUser } = currentUserSlice.actions
export default currentUserSlice.reducer;

@ -0,0 +1,18 @@
import { configureStore } from "@reduxjs/toolkit";
import currentUserReducer from "./features/currentUserSlice";
import { getDefaultMiddleware } from '@reduxjs/toolkit';
const customizedMiddleware = getDefaultMiddleware({
serializableCheck: false
})
const store = configureStore({
reducer: {
currentUser: currentUserReducer,
},
middleware: (getDefaultMiddleware) => customizedMiddleware,
})
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;
export default store;

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save