setup redux in react app
can someone help me setup redux in react app i am having trouble doing it
1 Reply
import React, { useState } from 'react'
import { useSelector } from 'react-redux'
function Count() {
const count = useSelector(state => state.count)
const [value , setValue] = useState(0)
console.log(count)
return (
<div>
{value}
</div>
)
}
export default Count
import React, { useState } from 'react'
import { useSelector } from 'react-redux'
function Count() {
const count = useSelector(state => state.count)
const [value , setValue] = useState(0)
console.log(count)
return (
<div>
{value}
</div>
)
}
export default Count
import { createSlice } from "@reduxjs/toolkit";
const initialState = {
count : [{
value:"1"
}]
}
export const countSlice = createSlice({
name:"count",
initialState,
reducers:{
countChange:(state,action)=>{
const counts = [{
value:action.payload
}]
state.count = counts
}
}
})
export const {countChange} = countSlice.actions
export default countSlice.reducer
import { createSlice } from "@reduxjs/toolkit";
const initialState = {
count : [{
value:"1"
}]
}
export const countSlice = createSlice({
name:"count",
initialState,
reducers:{
countChange:(state,action)=>{
const counts = [{
value:action.payload
}]
state.count = counts
}
}
})
export const {countChange} = countSlice.actions
export default countSlice.reducer
import { configureStore } from "@reduxjs/toolkit";
import {countSlice} from '../features/countSlice'
export const store = configureStore({
reducer:countSlice
})
import { configureStore } from "@reduxjs/toolkit";
import {countSlice} from '../features/countSlice'
export const store = configureStore({
reducer:countSlice
})