Javascript 如何使用React钩子在React Material UI的复选框中将数据传递为true

Javascript 如何使用React钩子在React Material UI的复选框中将数据传递为true,javascript,reactjs,checkbox,material-ui,Javascript,Reactjs,Checkbox,Material Ui,我试着开始,但我可能完全错了。 顺便说一句,复选框有一个标签“project\u in\u progress”。对不起,我的解释能力不好,我希望这是可以理解的。请帮忙。在我的情况下,我这样做了: const HandleProgressCheckbox = (project_in_progress) => { setProgressCheckbox({currentProject.project_in_progress ? true : false}), }; 我在我的项目中

我试着开始,但我可能完全错了。
顺便说一句,复选框有一个标签“project\u in\u progress”。对不起,我的解释能力不好,我希望这是可以理解的。请帮忙。

在我的情况下,我这样做了:

const HandleProgressCheckbox = (project_in_progress) => {
    setProgressCheckbox({currentProject.project_in_progress ? true : false}),
  };
我在我的项目中使用“redux”,如果您只需要使用一个“reactjs”就可以了,那么您需要:

handleChangeIsPublic = (e) => {
    const isChecked = e.target.checked;

    const { dispatch } = this.props;
    dispatch(actions.setPublicState(isChecked));
}
Upd:

我将您的版本修改为使用挂钩,结果如下:

handleChangeIsPublic = (e) => {
    const isChecked = e.target.checked;

    this.setState({
        isPublic: isChecked ? true : false,
    });
}
import React,{useState,useffect}来自“React”;
从“@material ui/core/Checkbox”导入复选框;
从“@material ui/core/FormControlLabel”导入FormControlLabel;
从“@material ui/core/Typography”导入排版;
导出默认函数projectnProgress(){
const[inProgress,setInProgress]=使用状态(false);
函数handleInProgressChange(e){
setInProgress(例如,目标已选中);
}
useffect(()=>{
如果(inProgress==真){
警报(`inProgress是${inProgress}`);
}
});
返回(
)
}

我希望我能帮助你。

你知道如何用钩子做一个吗?你能试着做一个功能组件吗?更新了我的答案
handleChangeIsPublic = (e) => {
    const isChecked = e.target.checked;

    const { dispatch } = this.props;
    dispatch(actions.setPublicState(isChecked));
}
handleChangeIsPublic = (e) => {
    const isChecked = e.target.checked;

    this.setState({
        isPublic: isChecked ? true : false,
    });
}
import React, { useState, useEffect } from 'react';

import Checkbox from '@material-ui/core/Checkbox';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import Typography from '@material-ui/core/Typography';

export default function ProjectInProgress() {
    const [inProgress, setInProgress] = useState(false);

    function handleInProgressChange(e) {
        setInProgress(e.target.checked);
    }

    useEffect(() => {
        if (inProgress === true) {
            alert(`inProgress is ${inProgress}`);
        }
    });

    return (
        <FormControlLabel
            value = "end"
            control = {
                        <Checkbox
                            onChange={handleInProgressChange}
                            checked={inProgress}
                            style={{ color: "#C8102E" }} />}
                            label={
                                    <Typography style={{ fontSize: 15 }}>
                                        Check if project "In Progress"
                                    </Typography>}
            labelPlacement="end"
        />
    )
}