小编Pra*_*idu的帖子

单选按钮需要单击两次以反映更改

1.每当我点击单选按钮时,它会调用handleOptionChange回调,但不会反映html的变化.2.但是当我在单选按钮上单击两次时,它反映了更改

我的问题是为什么我需要在单选按钮上单击两次?我做错了吗?

class CompleteProfile extends Component{

    constructor(props){
        super(props);
        this.state = {
            teacher_role:'subject'
        };
        this.handleOptionChange = this.handleOptionChange.bind(this);
    }

    handleOptionChange(event){
        event.preventDefault();
        let { name, value } = event.target;
        this.setState( { [name]:value } );
    }

    render(){
        let { teacher_role } = this.state;
        console.log('teacher:',teacher_role);
        return(
            <Wrapper className="complete-profile">
                <CustomContainer>
                    <Title>complete profile</Title>
                    <ProfileCard>
                        <Form noValidate>

                            <FormGroup>
                                <label>I want to enroll as:</label>

                                <label htmlFor="test">
                                    <input id="test" type="radio" name="teacher_role" value="subject" checked={ teacher_role === 'subject' } onChange={ this.handleOptionChange } />
                                    subject teacher
                                </label>

                                <label htmlFor="test1">
                                    <input id="test1" type="radio" name="teacher_role" …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

9
推荐指数
4
解决办法
4142
查看次数

如何将我的github repo链接添加到npm包中?

我需要将我的github存储库的链接添加到我的npm包中.我没有在npm文档中找到解决方案.

github npm

7
推荐指数
1
解决办法
1401
查看次数

为什么 hot-update.json 文件挤满了我的项目目录

在此处输入图片说明

为什么 hot-update.json 文件挤满了我的项目目录

每次当我使用这个命令在开发模式下运行 webpack,webpack -d --watch然后在 app.js 文件或任何其他文件中进行任何更改时,webpack 正在观察它编译它并在 dist 目录中添加hot-update.json文件。

webpack

2
推荐指数
1
解决办法
1110
查看次数

在反应样板中实现 axios 拦截器的最佳方式是什么?

我正在使用使用 fetch 库的 react 样板。但是现在我想实现拦截器,有没有人知道如何使用 fetch 库来实现它,或者我应该为此使用 axios。

fetch reactjs react-native axios react-boilerplate

1
推荐指数
1
解决办法
2531
查看次数