-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added redux persist blacklist example
- Loading branch information
IRONMTN\SShah.prt
committed
Jun 14, 2021
1 parent
b49d89d
commit 4e5fb02
Showing
6 changed files
with
140 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, {useState} from 'react'; | ||
import {View} from 'react-native'; | ||
import {Button, Text, TextInput, useTheme} from 'react-native-paper'; | ||
import {useDispatch, useSelector} from 'react-redux'; | ||
import {addStep} from '../redux/ageSlice'; | ||
|
||
export const Age = () => { | ||
const theme = useTheme(); | ||
// REDUX | ||
const count = useSelector(state => state.age.value); | ||
const dispatch = useDispatch(); | ||
|
||
return ( | ||
<> | ||
<View> | ||
<View style={{margin: 5}}> | ||
<Text style={{color: theme.colors.primary, fontSize: 20}}> | ||
Age Component (blacklist): {count} | ||
</Text> | ||
<Text style={{color: theme.colors.text, fontSize: 20}}> | ||
This value is blacklisted in our store's persistConfig, thus age | ||
won't persist. | ||
</Text> | ||
</View> | ||
<View style={{margin: 5}}> | ||
<TextInput | ||
mode="outlined" | ||
label="Your age" | ||
keyboardType="numeric" | ||
value={count} | ||
onChangeText={num => dispatch(addStep(num))} | ||
/> | ||
</View> | ||
</View> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, {useState} from 'react'; | ||
import {View} from 'react-native'; | ||
import {Button, Text, TextInput, useTheme} from 'react-native-paper'; | ||
import {useDispatch, useSelector} from 'react-redux'; | ||
import {rename} from '../redux/personSlice'; | ||
|
||
export const Person = () => { | ||
const theme = useTheme(); | ||
// REDUX | ||
const count = useSelector(state => state.person.value); | ||
const dispatch = useDispatch(); | ||
|
||
return ( | ||
<> | ||
<View> | ||
<View style={{flexDirection: 'row', margin: 5}}> | ||
<Text style={{color: theme.colors.primary, fontSize: 20}}> | ||
Person Component: {count} | ||
</Text> | ||
</View> | ||
<View style={{margin: 5}}> | ||
<TextInput | ||
mode="outlined" | ||
label="Your name" | ||
placeholder="Full name" | ||
value={count} | ||
onChangeText={text => dispatch(rename(text))} | ||
/> | ||
</View> | ||
</View> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {createSlice} from '@reduxjs/toolkit'; | ||
|
||
export const ageSlice = createSlice({ | ||
name: 'age', | ||
initialState: { | ||
value: '0', | ||
}, | ||
reducers: { | ||
addStep: (state, action) => { | ||
state.value = parseInt(action.payload ? action.payload : 0).toString(); | ||
}, | ||
}, | ||
}); | ||
|
||
// ACTIONS export | ||
export const {addStep} = ageSlice.actions; | ||
export default ageSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {createSlice} from '@reduxjs/toolkit'; | ||
|
||
export const personSlice = createSlice({ | ||
name: 'person', | ||
initialState: { | ||
value: '', | ||
}, | ||
reducers: { | ||
rename: (state, action) => { | ||
state.value = action.payload ? action.payload : ''; | ||
}, | ||
}, | ||
}); | ||
|
||
// ACTIONS export | ||
export const {rename} = personSlice.actions; | ||
export default personSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters