App.js
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, Button } from 'react-native';
import {store} from './redux/store';
import {Provider, useDispatch, useSelector} from 'react-redux';
import { increment_white } from './redux/counterWhiteSlice';
import Parts from './components/Parts';
function ContainerApp(){
</View>
<Text>黒</Text>
<Button
title='+'
onPress={() => dispatch(increment_black())}/>
</View>
</View>
)
}
const styles = StyleSheet.create({
container: {
alignItems: 'center',
justifyContent: 'center'
}
})
redux/store.js
import { configureStore } from "@reduxjs/toolkit";
import counterWhiteReducer from "./counterWhiteSlice";
import counterBlackReducer from "./counterBlackSlice";
export const store = configureStore({
//Reducerを定義
reducer: {
counter_white: counterWhiteReducer,
counter_black: counterBlackReducer,
}
})
redux/counterWhiteSlice.js
import { createSlice } from "@reduxjs/toolkit";
export const counterWhiteSlice = createSlice({
name: "counter_white",
initialState: {
},
reducers:{
increment_white: (state) =>{
}
}
})
export const {increment_white} = counterWhiteSlice.actions;
export default counterWhiteSlice.reducer;
redux/counterBlackSlice.js
import { createSlice } from "@reduxjs/toolkit";
export const counterBlackSlice = createSlice({
name: "counter_black",
initialState: {
},
reducers:{
increment_black: (state) =>{
}
}
})
export const {increment_black} = counterBlackSlice.actions;
export default counterBlackSlice.reducer;
return(
<View>
<Text>総数:{count}</Text>
<Parts/>
</View>
)
}
export default function App() {
return (
<Provider store={store}>
<View style={styles.container}>
<ContainerApp/>
<StatusBar style="auto" />
</View>
</Provider>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});