You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
736 B
25 lines
736 B
import React, { FC } from 'react'
|
|
import { useSelector, useDispatch } from 'react-redux'
|
|
|
|
import { setFieldValue } from 'src/actions/forms'
|
|
import { getFieldValue } from 'src/selectors/forms'
|
|
import { AppState } from 'src/types'
|
|
|
|
interface Props {
|
|
name: string
|
|
}
|
|
|
|
const CheckboxField: FC<Props> = ({ name, children }) => {
|
|
const value = useSelector<AppState, boolean>(state => getFieldValue<boolean>(state, name, false))
|
|
const dispatch = useDispatch()
|
|
|
|
return (
|
|
<label className="checkbox">
|
|
<input type="checkbox" checked={value} onChange={e => dispatch(setFieldValue(name, e.target.checked))} />
|
|
|
|
{children}
|
|
</label>
|
|
)
|
|
}
|
|
|
|
export default CheckboxField
|