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

59
Views
Component verification using Redux

In react, to verify and show a component, we do:

const [state, setState] = useState(false);

<button ... onClick={() => setState(true)} />

{state && <MyComponent />}

but what if I want to change this code to use redux?

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

0

You could use react-redux to achieve this, even though there's some boilerplate code required to set up your store if you don't have one yet.

You could do something like the following:

import { useSelector, useDispatch } from 'react-redux'
import { showViewAction } from './viewDisplaySlice'

export const MyComponent = () => {
  const shouldDisplayComponent = useSelector(state => state.shouldDisplay);
  const dispatch = useDispatch();

  return (
    ....
        <button
          onClick={() => dispatch(showViewAction())}
        >
          ...
        </button>
        { shouldDisplayComponent && <MyViewComponent /> }
    </div>
  );
};

You may find quick start guide helpful to setup store and using react-redux: https://redux.js.org/tutorials/quick-start

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!