如何将外部的类组件方法调用到功能组件 React 中?

时间:2021-07-01 09:12:07

标签: reactjs react-redux react-router

我想在外部调用类组件方法到另一个功能组件中。

`
**Component 1:**

class Demo extends Component {
constructor(props) {
        super(props);
this.login = this.login.bind(this);
}
login = () => {//Login logic
};
} 
export default Demo 

**Functional Component:**
import Demo from './Demo'; 
const DemoFunctional = (props) =>{const onChange = ()=>{Demo.login();};
}
`

我已经尝试过 window 对象,但是当单击功能区图标时它会卸载。我已关注此Call a React component method from outside

请提供好的解决方案,因为我们的业务停滞不前。

0 个答案:

没有答案