Created
August 12, 2021 11:16
-
-
Save riyastir/216315b685bb1477574225993a5ee680 to your computer and use it in GitHub Desktop.
State issue - Redux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const [candidateParties, setCandidateParties] = useState([]); | |
const dispatch = useDispatch(); | |
const currentParty = useSelector(currentSelectedParty); | |
useEffect(() => { | |
(async () => { | |
await fetch(`http://localhost:3000/api/v1/candidates/parties`) | |
.then((res) => res.json()) | |
.then((result) => { | |
setCandidateParties(result.parties); | |
}); | |
})(); | |
}, []); | |
const dispatchNewParty = (party) => { | |
dispatch(changeParty(party)); | |
}; | |
return ({ | |
candidateParties.map((data, key) => { | |
return ( < | |
button key = { | |
key | |
} | |
type = "button" | |
onClick = { | |
() => { | |
dispatchNewParty(data); | |
} | |
} | |
data - filter = ".blue" | |
className = { | |
currentParty === data ? | |
"control mixitup-control-active" : | |
"control" | |
} > | |
{ | |
data | |
} </button> | |
); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment