Guest User

Untitled

a guest
Jul 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import React from 'react';
  2. import UserAuthenticationUI from './UserAuthentication/UserAuthenticationUI';
  3. import UserAuthenticationRequests from './UserAuthentication/UserAuthenticationRequests';
  4.  
  5. class App extends React.Component {
  6. constructor(props) {
  7. super(props);
  8.  
  9. this.userAuthenticationUI = React.createRef();
  10. this.userAuthenticationRequests = React.createRef();
  11. }
  12.  
  13. componentDidMount(){
  14. this.userAuthenticationRequests.current.testMethod(); //there i can call method without problems
  15. }
  16.  
  17. render(){
  18. return(
  19. <div>
  20. <UserAuthenticationUI ref={this.userAuthenticationUI} />
  21. <UserAuthenticationRequests ref={this.userAuthenticationRequests} />
  22. <div>
  23. )}
  24. }
  25. export default App;
  26.  
  27. import React from "react";
  28. import App from '../App';
  29. import UserAuthenticationRequests from './UserAuthenticationRequests';
  30.  
  31. class UserAuthenticationUI extends React.Component
  32. {
  33. constructor(props){
  34. super(props);
  35.  
  36. this.app = React.createRef();
  37. this.userAuthenticationRequests = React.createRef();
  38. }
  39.  
  40. componentDidMount() {
  41.  
  42. this.userAuthenticationRequests.current.testMethod(); //there i can not call
  43. }
  44.  
  45. render(){
  46. <App/>
  47. <UserAuthenticationRequests ref={this.userAuthenticationRequests} />
  48. return(
  49. <div>
  50.  
  51. </div>
  52. )}
  53. }
  54.  
  55. export default UserAuthenticationUI;
  56.  
  57. TypeError: Cannot read property 'testMethod' of null
  58.  
  59. testMethod(){
  60. console.log("test method")
  61. }
  62.  
  63. render(){
  64. return(<div></div>)
  65. }
  66. }
  67. export default UserAuthenticationRequests;
Add Comment
Please, Sign In to add comment