How to call a method in the React component in an external script

Enda

I would like to call in the external script, or console React components of the method

I tried to do so

componentDidMount(){
    window.mwap = this;
}

but no use

enter image description here

please help me

rossipedia

The return value of ReactDOM.render() is actually the mounted instance of the component:

class Counter extends React.Component {
  
  constructor(props) {
    super(props);
    this.state = {
      count: 0
    };
  }
  
  inc() {
    this.setState({count: this.state.count + 1});
  }
  
  render() {
    return (
        <div>
          Count: {this.state.count}
        </div>
    )
  }
}

const instance = ReactDOM.render(
  <Counter />,
  document.getElementById('app')
);

instance.inc();
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>

<div id="app"></div>

If you need access to a deeply nested component, that's a bit more difficult, but this should get you started.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to call the parent Method in child class component in react

From Java

Call a React component method from outside

From Dev

How to call an external script from .gitconfig alias?

From Dev

How to call an external object through a method

From Dev

How React Component expose data to external app?

From Dev

How React Component expose data to external app?

From Dev

Angular 2 How to call a component method from index.html(script)?

From Dev

React call component's method from nested function in render method

From Dev

Angular 2: How to call the method on a nested component?

From Dev

How to call a method of the component that Navigator has mounted?

From Dev

How to call external method from nested ajax (success) method?

From Dev

How can I call method in child component from parent component?

From Dev

How to call minimize() and focus() in a React component?

From Dev

How to call a full html page into a React component

From Dev

React Native: How does this Component call?

From Dev

how to call a function from another component in react

From Dev

How to call a cmake method from shell script?

From Dev

call instance method from higher order component in react

From Dev

What is the correct way to call a component method in many other components in React?

From Dev

call instance method from higher order component in react

From Dev

Why does React call the render method of an unchanged component?

From Dev

How to call a django view function from external python script

From Dev

How to call a django view function from external python script

From Dev

How do you call a component in another component in react?

From Dev

How do you call a component in another component in react?

From Java

Call parent method with component

From Java

Call a method of the child component

From Dev

Call method of a component in directive

From Dev

How to call external javascript method on aspx page in the user control

Related Related

  1. 1

    How to call the parent Method in child class component in react

  2. 2

    Call a React component method from outside

  3. 3

    How to call an external script from .gitconfig alias?

  4. 4

    How to call an external object through a method

  5. 5

    How React Component expose data to external app?

  6. 6

    How React Component expose data to external app?

  7. 7

    Angular 2 How to call a component method from index.html(script)?

  8. 8

    React call component's method from nested function in render method

  9. 9

    Angular 2: How to call the method on a nested component?

  10. 10

    How to call a method of the component that Navigator has mounted?

  11. 11

    How to call external method from nested ajax (success) method?

  12. 12

    How can I call method in child component from parent component?

  13. 13

    How to call minimize() and focus() in a React component?

  14. 14

    How to call a full html page into a React component

  15. 15

    React Native: How does this Component call?

  16. 16

    how to call a function from another component in react

  17. 17

    How to call a cmake method from shell script?

  18. 18

    call instance method from higher order component in react

  19. 19

    What is the correct way to call a component method in many other components in React?

  20. 20

    call instance method from higher order component in react

  21. 21

    Why does React call the render method of an unchanged component?

  22. 22

    How to call a django view function from external python script

  23. 23

    How to call a django view function from external python script

  24. 24

    How do you call a component in another component in react?

  25. 25

    How do you call a component in another component in react?

  26. 26

    Call parent method with component

  27. 27

    Call a method of the child component

  28. 28

    Call method of a component in directive

  29. 29

    How to call external javascript method on aspx page in the user control

HotTag

Archive