Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
Cant get redux state from component

Simple counter app.State is changing as expected when button clicked ,which I can track in redux dev tools.However I cant access the count redux state from the counter component.What am I doing wrong exactly?

import React,{useState} from 'react'
import { connect } from 'react-redux';
import  addone from '../actions/addone';



const Counter = ({addone,count}) => {
    
    console.log(count);
    return (
        <div>
            <h1>Value:{count}</h1>
            <button type="button" onClick={()=>addone()}>Add 1</button>

        </div>
    )
}


const mapStateToProps = (state) => ({
    count:state.count
  });

export default connect(mapStateToProps, { addone })(Counter);

output nothing is shown after value.

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you need to use useSelector hook in functional components i edited your code:

import React,{useState} from 'react';
import { useSelector} from 'react-redux';
import  addone from '../actions/addone';

const Counter = () => {
    const count = useSelector((state) => state.count);
    console.log(count);
    return (
        <div>
            <h1>Value:{count}</h1>
            <button type="button" onClick={()=>addone()}>Add 1</button>

        </div>
    )
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!