简体   繁体   English

如何修复React中的'_this4.props.handleExport'错误

[英]How to fix '_this4.props.handleExport' error in React

I use a handleExport function in the parent component set in a child under child component. 我在子组件下的子组件中的父组件集中使用handleExport函数。 However, the error below occurs and that would not work well. 但是,出现以下错误,并且无法正常工作。

_this4.props._handleExport is not a function _this4.props._handleExport不是函数

src/components/PrimaryItem.js

export default class PrimaryItem extends Component {
  render() {
    return (
      <Stage
        ref={ref => {
          this.props._handleExport(ref);
        }}
      >
      </Stage>
    );
  }
}

src/components/PrimaryContainer.js

import PrimaryItem from "./PrimaryItem";


<PrimaryContainer
  _handleExport={this._handleExport}
/>

src.App.js

import PrimaryItem from "./components/PrimaryContainer";

export default class App extends component {
  _handleExport = ref => {
    if (ref) {
      this.refStage = ref;
    }
  };
  render() {

  return(
  <PrimaryContainer 
    _handleExport={this._handleExport}
  />
  )
}
}

You can bubble up requests through props passed into child containers like so. 您可以像这样通过传递到子容器中的道具增加请求。

// --- parent.js

import React, { Component, Fragment } from "react";
import { ChildComponent } from './containers/child'

export class ParentContainer extends Component {

  handleUpdate = () => {
    // whatever you want to do here
    console.log('I have been clicked from ChildContainer')
  }

  render() {
    return (
      <Fragment>
        <ChildComponent onUpdate={this.handleUpdate} />
      </Fragment>
    );
  }
}

// --- child.js

import React, { Component, Fragment } from "react";

export class ChildComponent extends Component {

  constructor(){
    super()
    console.log(this.props) // will show you the props you have access to pass into components.
  }

  render() {
    return (
      <button onClick={this.props.onUpdate}></button>
    );
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复React.js中的箭头功能以与道具一起使用 - How to fix arrow function in React.js to work with props 如何修复 TypeError:this.props.changeCategory 在 React 中不是 function? - How to fix TypeError: this.props.changeCategory is not a function in React? 如何修复反应中的错误(不是函数) - how to fix the error (is not a function) in react 如何用单个道具用括号修复更漂亮和更薄的错误? - How to fix prettier and tslint error with brackets with single props? React + PropTypes和ESlint错误:如何验证回调的道具 - React + PropTypes and ESlint error: How to validate props of a callback 反应错误 - “道具验证中缺少” - React error - “is missing in props validation” 如何发送道具与道具组件反应 - how to send props with props component react 如何解决React Native中的导航问题(TypeError:undefined不是一个对象(评估&#39;_this.props.navigation)) - How to fix navigation problem in React Native (TypeError: undefined is not an object (evaluating '_this.props.navigation) 如何修复 localhost 中的反应 cors 错误? - How to Fix react cors error in localhost? Typescript 类型检查错误如何在 React 中修复 - Typescript type checking error how to fix in React
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM