0% found this document useful (0 votes)
12 views32 pages

Lecture 05 JavaScript Library For Building Web UI - React

Uploaded by

trzong-ming.teoh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views32 pages

Lecture 05 JavaScript Library For Building Web UI - React

Uploaded by

trzong-ming.teoh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

JavaScript library

for building web


user interface
React

https://react.dev/
React UI components
How does React Work?
React Directly in HTML

https://unpkg.com/react@18/umd/react.development.js
https://unpkg.com/react-dom@18/umd/react-dom.development.js

https://unpkg.com/@babel/standalone/babel.min.js
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/react@18/umd/react.development.js"
crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"
crossorigin></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>

<div id="mydiv"></div>

<script type="text/babel">
function Hello() {
return <h1>Hello World!</h1>;
}

const container = document.getElementById('mydiv');


const root = ReactDOM.createRoot(container);
root.render(<Hello />)
</script>

</body>
</html>
React Getting Started

https://nodejs.org/en/download
Setting up a React Environment

https://create-react-app.dev/docs/getting-started
https://github.com/facebook/create-react-app
move to the my-react-app directory:

create-react-app
create-react-app (cont.)
http://localhost:3000
How to Fix npx Create-react-app error

https://www.youtube.com/watch?v=el6379gVCaU
Modify the React Application
Modify App.js
Index.js in React
React Render HTML
React Render HTML (cont.)
index.html file
Example: Display a paragraph inside an
element with the id of "root"
React JSX
With and Without JSX
React DOM
React DOM (cont.)
https://react.dev/reference/react/hooks
https://react.dev/reference/react/components
https://react.dev/reference/react/apis
React components
Rules of React
JSX rules
React Fragments (<>...</>)

<PostTitle />
<PostBody />
JSX file extensions
JSX syntax
Evaluating JS expressions in JSX
Where to use curly braces { }

https://react.dev/learn/javascript-in-jsx-with-curly-
braces
Using “double curlies”: CSS and other
objects in JSX
Example: inline css styles using {{ }}

You might also like