//

Saturday, July 6, 2019

Rendering Elements

React Elements

React Elements are objects that represent a DOM node. They are written using a syntax extension named JSX which we will cover later in this module. React Elements are different than React Components, which we will also cover later in this module.

    var element = <h1>Hello World!</h1>
React Elements need to be rendered by the ReactDOM.render() method to appear in the DOM.

ReactDOM.render()

The ReactDOM.render() method is used to render a React Element into a specified part of the HTML DOM. In most React applications, there is usually a single root node where everything gets rendered into, but you may use as many root nodes as you desire.
In this case, the <h1>Hello World!</h1> React Element is rendered into the DOM element with the id of "root".
   <div id="root"></div>

    ReactDOM.render(
        <h1>Hello World!</h1>,
        document.getElementById("root")
    )

Rerendering the DOM using additional render() calls

Once a DOM is rendered, it will remain the same until another render() method is called.
The following example uses additional render() calls to update the displayed number:

    var num = 0;

    function updateNum(){

        ReactDOM.render(
            <div>{num++}</div>,
            document.getElementById("root")
        )
    }

   setInterval(updateNum,100)

1 comment:

  1. Ref: https://courses.edx.org/courses/course-v1:Microsoft+DEV281x+1T2019a/courseware/8aeb17a4bc2d4ef7bba69a7c298f7f57/0c8e21db7eaa49028aa9e9a847497263/1?activate_block_id=block-v1%3AMicrosoft%2BDEV281x%2B1T2019a%2Btype%40vertical%2Bblock%404cdcd180e2a74b278b8f3eb8467afe4d

    ReplyDelete

Effective Branching Strategies in Development Teams

Effective Branching Strategies in Development Teams Effective Branching Strategies in Developme...