Select Git revision
Forked from
SOFT Core / SOFT 260 / React Redux Starter Code
4 commits behind, 1 commit ahead of the upstream repository.
Brady James Garvin authored
counter.js 750 B
import { useSelector, useDispatch } from 'react-redux';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import styles from './counter.module.css';
import {
selectValue,
setValue,
} from './counterSlice.js';
export function Counter(props) {
const value = useSelector(selectValue);
const dispatch = useDispatch();
const classes = classNames({
[styles.red]: value % 2 === 0,
[styles.blue]: value % 2 === 1,
});
const onClick = () => dispatch(setValue({
value: value + 1,
}));
return (
<label>
{props.label}:
<button className={classes} onClick={onClick}>
{value}
</button>
</label>
);
}
Counter.propTypes = {
label: PropTypes.string.isRequired,
};