'React native redux toolkit?
I am currently working on project where i have to use redux. I have used redux and redux toolkit both but at some stage both are not working. REDUX TOOLKIT: I have this Slice
import { createSlice } from '@reduxjs/toolkit';
const initialState = {
restname: '',
checked: [],
};
export const cartSlice = createSlice({
name: 'cart',
initialState,
reducers: {
checkbox: (state, action) => {
const { checkboxValue } = action.payload;
if (checkboxValue) {
console.log('ADD TO CART', checkboxValue);
state.checked.push(action.payload.item);
console.log('pressed', state);
} else {
state.checked.filter((item) => item.name !== 'one');
console.log('deleted', state.checked);
}
},
cartPressed: (state, action) => {
(state.restname = action.payload), console.log(state);
},
},
});
export const selectChecked = (state) => state.cart.selectedItem;
// Action creators are generated for each case reducer function
export const { checkbox, cartPressed } = cartSlice.actions;
export default cartSlice.reducer;
I am deleting value when check box is uncheked but it does not deletes it from state here is output:
pressed {"restname":"","checked":[{"name":"one"}]} Chrome: item true Chrome: ADD TO CART true Chrome: pressed {"restname":"","checked":[{"name":"one"},{"name":"two"}]} Chrome: item true Chrome: deleted {"restname":"","checked":[{"name":"one"},{"name":"two"}]} Chrome: item false
when i delete it it does nothing
{abc.map((item) => (
<BouncyCheckbox
text={item.name}
style={{ padding: 2 }}
iconStyle={{
borderColor: 'lightgray',
borderRadius: 0,
}}
fillColor="red"
unfillColor="#FFFFFF"
onPress={(checkboxValue) => {
dispatch(checkbox({item:item,checkboxValue}))
console.log('item',checkboxValue);
}}
/>
))}
abc is nothing but an array=> let abc = [{name:'one'}, {name:'two'}, {name:'three'},{name: 'four'}];
I am working in react native Here is expo link enter link description here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
