Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 作为道具传递的函数在子组件中未定义,但在道具对象中可见_Javascript_Reactjs - Fatal编程技术网

Javascript 作为道具传递的函数在子组件中未定义,但在道具对象中可见

Javascript 作为道具传递的函数在子组件中未定义,但在道具对象中可见,javascript,reactjs,Javascript,Reactjs,我将几个函数作为道具传递给子组件,但是我传递的onSubmit函数在子组件中未定义。但是,如果我在子组件中记录this.props,我可以看到onSubmit已定义 我传递的其他函数都工作正常,所以我不确定这个函数是否有问题 这是有问题的onSubmit函数: onSumbit = (event) => { const { email, passwordOne, name, schedule, } = this.state; const creat

我将几个函数作为道具传递给子组件,但是我传递的
onSubmit
函数在子组件中未定义。但是,如果我在子组件中记录
this.props
,我可以看到
onSubmit
已定义

我传递的其他函数都工作正常,所以我不确定这个函数是否有问题

这是有问题的
onSubmit
函数:

onSumbit = (event) => {
    const {
        email, passwordOne, name, schedule,
    } = this.state;

    const createUserData = (authUser) => this.props.firebase
        .user(authUser.user.uid)
        .set({
            type: 'Venue',
        });

    const createVenueData = (authUser) => {
        const placeLocation = this.state.place.geometry.location;
        const placeAddress = this.state.place.address_components;

        if (!placeLocation) {
            return Promise.reject(
                new Error('No coordinates for location, please use Google Autocomplete to select address'),
            );
        }

        return this.props.firebase.venues().add({
            uid: authUser.user.uid,
            email: authUser.user.email,
            name,
            schedule: JSON.parse(schedule),
            address: placeAddress,
            coordinates: new this.props.firebase.firestore
                .GeoPoint(placeLocation.lat(), placeLocation.lng()),
        });
    };

    this.props.firebase
        .doCreateUserWithEmailAndPassword(email, passwordOne)
        .then((authUser) => Promise.all([createUserData(authUser), createVenueData(authUser)]))
        .then(() => {
            this.setState({ ...INITIAL_STATE });
            this.props.history.push(ROUTES.HOME);
        })
        .catch((error) => {
            this.setState({ error });
        });

    event.preventDefault();
}
这是父组件中的渲染函数,我将在其中传递Submit:

render() {
    console.log("ON SUBMIT");
    console.log(this.onSumbit);
    console.log(this.handleInputChange);
    return (
        <SignUp
            handleInputChange={this.handleInputChange}
            validate={this.validate}
            validationSchema={signUpSchema}
            onSumbit={this.onSumbit}
            addressRef={this.addressRef}
            error={this.state.error}
        />
    );
} 
render(){
控制台。登录(“提交时”);
console.log(this.onSumbit);
console.log(this.handleInputChange);
返回(
);
} 

typo-在Sumbit上而不是onSubmit@OriDrori哦,真尴尬。谢谢你指出这一点!如果你把它写下来作为回答,我会接受它作为工作的正确部分:)