M
M
Martovitskiy2021-07-05 13:13:36
React
Martovitskiy, 2021-07-05 13:13:36

Why isn't checked checked?

constructor(props) {
        super(props);
        const value = props.value || {};
        this.state = {
            value,
            iconLoading: false,
            isVisible: props.isVisible,
            checked: true,
            isEdit: !!props.data,
            types: [],
            isChecked: props.checked,
            data: props.data,
            name: '',
            email: '',
        }
        this.handleChange = this.handleChange.bind(this);
    }

    componentDidMount() {
        setPageSettings({
            title: 'Создание и предоставление разрешений'
        });
        this.setState({isLoading: true});
        this.fetch();
    }
toggleChecked = () => {
        this.setState({ checked: !this.state.checked });
    };

    toggleDisable = () => {
        this.setState({ disabled: !this.state.disabled });
    };

    onChange = e => {
        console.log('checked = ', e.target.checked);
        this.setState({
            checked: e.target.checked,
        });
    };

fetch = () => {
return api
            .get(`/permissions`)
            .then(response => {
                this.setState({permissions: response.data});
            })
            .catch(e => {
                this.setState({permissions: []});
            });

render() {
     const {iconLoading, permissions, userData, isLoading} = this.state;
    // в форме
<Checkbox value={row.id} key={row.id} checked={this.state.checked}>
                                                            {row.id}
                                                        </Checkbox>
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Zhivagin, 2021-07-05
@Krasnodar_etc

Because you haven't passed onChange anywhere?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question