useSelector() in Redux not rendering new value ❓

I am learning redux , so made a demo webApp and in that I am incrementing and decrementing the value by 1 on button click . The problem is useSelector() hook in redux get fired once when the component is mounted but after that it doesn't re-render the changed value .. Here is the code :-> Reducer :
import { Action_Types } from "./value.types"


const Initial_State = {
Test_Value: 0
}

export const Value_Reducer = (state = Initial_State, action) => {
const { type, payload } = action

switch (type) {
case Action_Types.Set_Test_Value:
return {
...state,
Test_Value: payload
}
default:
return state
}
}
import { Action_Types } from "./value.types"


const Initial_State = {
Test_Value: 0
}

export const Value_Reducer = (state = Initial_State, action) => {
const { type, payload } = action

switch (type) {
case Action_Types.Set_Test_Value:
return {
...state,
Test_Value: payload
}
default:
return state
}
}
and the main File :
import React, { useEffect } from 'react'
import { Set_Test_Value } from './store/value/value.actions'
import { useDispatch } from 'react-redux'
import { useSelector } from 'react-redux'

function Test1() {

const dispatch = useDispatch()

const Test_Value = useSelector((state)=>state.value.Test_Value)


const Increment = ()=>{
console.log(Test_Value)
dispatch(Set_Test_Value(Test_Value+1))
}

const Decrement = ()=>{
if (Test_Value > 0) {
dispatch(Set_Test_Value(Test_Value-1))
}
}

useEffect(()=>console.log(Test_Value),[Test_Value])

return (
<>
<h1>test1</h1>
<input type="number" value={Test_Value} readOnly={true}/>
<button onClick={Increment}>Increment</button>
<button onClick={Decrement}>Decrement</button>
</>
)
}

export default Test1
import React, { useEffect } from 'react'
import { Set_Test_Value } from './store/value/value.actions'
import { useDispatch } from 'react-redux'
import { useSelector } from 'react-redux'

function Test1() {

const dispatch = useDispatch()

const Test_Value = useSelector((state)=>state.value.Test_Value)


const Increment = ()=>{
console.log(Test_Value)
dispatch(Set_Test_Value(Test_Value+1))
}

const Decrement = ()=>{
if (Test_Value > 0) {
dispatch(Set_Test_Value(Test_Value-1))
}
}

useEffect(()=>console.log(Test_Value),[Test_Value])

return (
<>
<h1>test1</h1>
<input type="number" value={Test_Value} readOnly={true}/>
<button onClick={Increment}>Increment</button>
<button onClick={Decrement}>Decrement</button>
</>
)
}

export default Test1
4 Replies
Dev_Maruti
Dev_Maruti2y ago
Please help me out , I am tired of trying different methods from last 2 days , I am using old version of redux in reactjs ( "react-redux": "^7.2.6" , "redux": "^4.1.2" )
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Dev_Maruti
Dev_Maruti2y ago
@acemouty Thanks buddy for stepping in . 🙏 This is my repo link it's just a very small test project , In this I am trying to increment and decrement the value by 1 in test1 file and see the result in input tag which takes the value from redux , please ignore test2 file its of no use ( I forgot to delete it ) , The branch is : Redux-Basics https://github.com/agroot2002/React-State-Management/tree/Redux-Basics I will be very happy if you have a look and help me out ... Thank You 😊
GitHub
GitHub - agroot2002/React-State-Management at Redux-Basics
In this repo you will get various methods of sharing value among the different components in reactjs ..... - GitHub - agroot2002/React-State-Management at Redux-Basics
Dev_Maruti
Dev_Maruti2y ago
And I am not using Redux Toolkit I am using the before version of Redux for tutorial and practice purpose 👍
Want results from more Discord servers?
Add your server
More Posts
Hello I've been trying to figuring out how to make a link that lets people email you.Hello I've been trying to figuring out how to make a link that lets people email you. like that linkhow to paste something into an input from clipboard without using document.ExecCommand('paste') ?how to paste something into an input from clipboard without using document.ExecCommand('paste') sincneed a library that helps me to resize the window (we want the layout like codesandbox).hey! everyone... I'd like to ask you a question: I'm looking for a library that will allow me to resCSSComb for nowadays SASSi work for a long time now with a tool called CSSComb that allows me to order my CSS declarations inI want to extend builtin HTML element classes (I know why you shouldn't and cant)`class MyCanvas extends HTMLCanvasElement` is obviously out of the question, but there's surely someHow can I align some paragraphs to start at the centered title's starting pointI am working on this the whole day, still can't manage to do it. The problem is I have titles in my flowHi Gays, I found this code but I don't know what it does : ```css .flow > *:where(:not(:first-child)how do i get input values inputted into input field 'in real-time' and use the input values?here's code i've tried: ```tipButtons.forEach(tipButton => { tipButton.addEventListener('click'make input field expand verticallyhi, i want to make my input field expand vertically when the text overflows, i attached a quick videCan strips pre-built checkout only be used surrounded by a form attribute?I’m having trouble integrating stripe using firebase. My code seems correct but every time I click “