我想在外部调用类组件方法到另一个功能组件中。
`
**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
请提供好的解决方案,因为我们的业务停滞不前。