Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import UserAuthenticationUI from './UserAuthentication/UserAuthenticationUI';
- import UserAuthenticationRequests from './UserAuthentication/UserAuthenticationRequests';
- class App extends React.Component {
- constructor(props) {
- super(props);
- this.userAuthenticationUI = React.createRef();
- this.userAuthenticationRequests = React.createRef();
- }
- componentDidMount(){
- this.userAuthenticationRequests.current.testMethod(); //there i can call method without problems
- }
- render(){
- return(
- <div>
- <UserAuthenticationUI ref={this.userAuthenticationUI} />
- <UserAuthenticationRequests ref={this.userAuthenticationRequests} />
- <div>
- )}
- }
- export default App;
- import React from "react";
- import App from '../App';
- import UserAuthenticationRequests from './UserAuthenticationRequests';
- class UserAuthenticationUI extends React.Component
- {
- constructor(props){
- super(props);
- this.app = React.createRef();
- this.userAuthenticationRequests = React.createRef();
- }
- componentDidMount() {
- this.userAuthenticationRequests.current.testMethod(); //there i can not call
- }
- render(){
- <App/>
- <UserAuthenticationRequests ref={this.userAuthenticationRequests} />
- return(
- <div>
- </div>
- )}
- }
- export default UserAuthenticationUI;
- TypeError: Cannot read property 'testMethod' of null
- testMethod(){
- console.log("test method")
- }
- render(){
- return(<div></div>)
- }
- }
- export default UserAuthenticationRequests;
Add Comment
Please, Sign In to add comment