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

91
Views
I have a problem in using mapStateToProps

I am practicing the react-redux. I wonder what is the difference between these two codes. I think these have same meaning, but the first code is not working well. The first one cannot deliver the props of the state. I removed the "import" part in this post

const TodosContainer = ({
    input,
    todos,
    changeInput,
    insert,
    toggle,
    remove
}) => {
    return (<Todos
        input={input}
        todos={todos}
        onChangeInput={changeInput}
        onInsert={insert}
        onToggle={toggle}
        onRemove={remove} />);
};
// from this point, I changed this code into below one
const mapStateToProps = state => ({ // in this part, I think it cannot send props
    input: state.todos.input,
    todos: state.todos.todos
});
const mapDispatchToProps = dispatch => ({
    changeInput: () => {
        dispatch(changeInput());
    },
    insert: () => {
        dispatch(insert());
    },
    toggle: () => {
        dispatch(toggle());
    },
    remove: () => {
        dispatch(remove());
    }
});
export default connect(
    mapStateToProps,
    mapDispatchToProps)(TodosContainer);

export default connect(
    ({ todos }) => ({
        input: todos.input,
        todos: todos.todos,
    }),
    {
        changeInput,
        insert,
        toggle,
        remove,
    }
)(TodosContainer); 

about 4 years ago · Juan Pablo Isaza
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!