MilosTanaskovic / React-CodeDancing

0 stars 0 forks source link

React CodeDancing - Basics & JSX #2

Open MilosTanaskovic opened 2 years ago

MilosTanaskovic commented 2 years ago

React CodeDancing - Basics & JSX

*Feedback UI App Screenshot 2022-04-05 at 14 14 29 *Feedback UI App - Figma design prototype Screenshot 2022-04-05 at 15 29 45

MilosTanaskovic commented 2 years ago

Feedback UI App (Entry Level)

This is going to allow us to touch on everything from:

MilosTanaskovic commented 2 years ago

create react app

getting started with React https://create-react-app.dev/docs/getting-started npx create-react-app feedback-app --use-npm cd feedback-app Inside that directory, you can run several commands: npm start Starts the development server. npm run build Bundles the app into static files for production. npm test Starts the test runner.

MilosTanaskovic commented 2 years ago

Initializing React

remove all files from src folder create index.js file

  • import react
  • import react-dom
  • ReactDom.render() - takes 2. parameters (<App/>,document.getElementById('root'))
  • wrapp App with <React.StrictMode><App/></React.StrictMode>

create App.js (main component in app)

  • import react
  • create functional component
  • return (JSX)

create global index.css

MilosTanaskovic commented 2 years ago

Intro To JSX

JSX is syntactic sugar JSX elements must be wrapped in an enclosing tag use <></> fragment to wrapp 2 or more elements there are some diff betwen HTML and JSX attribute (class - className, for - htmFor) JSX under the hood:


import React from 'react'

export default function App() { return React.createElement( 'div', { className: 'container' }, React.createElement('h1', {}, 'My App') ) }



### Dynamic Values & Lists in JSX

> use `{}` for dynamic (js) values...
> Above return store state, js, logic...

### Conditionals in JSX
> use `{}` for conditionals rendering
> use `&&` for conditionals rendering
> use `? :` for conditionals rendering