React script assistance

Where is My Component being called the first time in the following script?

Import React from 'react';
import { render } from 'react-dom';

import MyComponent from './MyComponent';

const myComponent = render(<MyComponent />, document.getElementById('root'));

setTimeout(() => {
  myComponent.setState({
    heading: 'React Awesomesauce',
    content: 'Done!'
  });
}, 3000);

Thx!

Not to be rude, but it shouldn’t matter because you should only talk to your components through their props not by manipulating their state directly.

I don’t think this code will even work, but if it does it probably has issues with hook based components which are the suggested method for building components.

Hi it’s just an example from a book - they are building up to the correct method and demonstrating points along the way - I think o get it .

They call the function and assign it to a variable after (I think)

Generally speaking though – set a breakpoint (or put a debugger statement) in the constructor and examine the call stack in your brwoser dev tools. :-)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.