Skip to content

S1 - L11 - Render Targets #2

@ngminhtrung

Description

@ngminhtrung
import React from 'react'; 
import ReactDOM from 'react-dom';

const App = function() {
   return <div>Hi!</div>;
}

ReactDOM.render(<App />);

Báo lỗi: Đoạn code trên báo lỗi bởi ReactDOM render một instance của class App, nhưng không chỉ rõ là thẻ <div>Hi!</div> mới sẽ được gắn vào đâu.

Sửa lỗi: Vậy lúc nào cũng cần chỉ rõ "điểm đến" của component trong HTML. Trong trường hợp này, giả sử muốn gán vào thẻ <div> với class là container nằm trong body, ta có thể làm như sau:

const mount = document.querySelector('.container');
ReactDOM.render(<App />, mount);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions