=
re renders
if we click button eventhougw we not calling
we can observer in closnel
=
tods.js
=
solved with memo
if not calls this todos it console not prints
=
=
re renders
if we click button eventhougw we not calling
we can observer in closnel
=
tods.js
=
solved with memo
if not calls this todos it console not prints
=
=
npm i -D react-router-dom
import ReactDOM from "react-dom/client";import { BrowserRouter, Routes, Route } from "react-router-dom";import Layout from "./Car";export default function App() {return (<BrowserRouter><Routes><Route path="/" element={<Layout />}></Route></Routes></BrowserRouter>);}const root = ReactDOM.createRoot(document.getElementById('root'));root.render(<App />);
=
==
created variables inputs and setinputs
in input value is varaible inputs.
on change call funciton
call handlechange
setInputs(values => Object.assign({}, values, { [name]: value }));
assigne the values to this object
=
=
ist mycar value loaded with volvo on page load normally it shows which one is ist value in drio down because of loaded value it showign as loaded value
function MyForm() {
const [myCar, setMyCar] = useState("Volvo");
const handleChange = (event) => {
setMyCar(event.target.value)
}
return (
<form>
<select value={myCar} onChange={handleChange}>
<option value="Ford">Ford</option>
<option value="Volvo">Volvo</option>
<option value="Fiat">Fiat</option>
</select>
</form>
)
}=
In this component:
Initial Value:
myCar is initialized with "Volvo" using useState("Volvo"), so "Volvo" is the default value for the myCar state when the page first loads.Select Element:
<select> element has a value prop set to myCar. Because myCar is initialized as "Volvo", the select dropdown will display "Volvo" as the selected option on page load.Changing the Selection:
handleChange function updates myCar to the selected option’s value, and the dropdown updates accordingly.So, even though "Ford" is the first option in the list, "Volvo" will display as selected initially because myCar was set to "Volvo" on load. This behavior is expected and correct.
=
=
function Car(props) {
return <li>I am a { props.brand }</li>;
}
function Garage() {
const cars = [
{id: 1, brand: 'Ford'},
{id: 2, brand: 'BMW'},
{id: 3, brand: 'Audi'}
];
return (
<>
<h1>Who lives in my garage?</h1>
<ul>
{cars.map((car) => <Car key={car.id} brand={car.brand} />)}
</ul>
</>
);
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Garage />);=
=
function Garage(props) {
const cars = props.cars;
return (
<>
<h1>Garage</h1>
{cars.length > 0 &&
<h2>
You have {cars.length} cars in your garage.
</h2>
}
</>
);
}
const cars = ['Ford', 'BMW', 'Audi'];
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Garage cars={cars} />);=
ternary
{ isGoal ? <MadeGoal/> : <MissedGoal/> }=
=
function Goal(props) {
const isGoal = props.isGoal;
if (isGoal) {
return <MadeGoal/>;
}
return <MissedGoal/>;
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Goal isGoal={false} />);=
react events
=
function Football() {
const shoot = () => {
alert("Great Shot!");
}
return (
<button onClick={shoot}>Take the shot!</button>
);
}
const root = ReactDOM.createRoot(document.getElementById('root')); root.render(<Football />);-
=
function Football() {
const shoot = (a) => {
alert(a);
}
return (
<button onClick={() => shoot("Goal!")}>Take the shot!</button>
);
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Football />);=
guess what is the event
=
import React from 'react';
import ReactDOM from 'react-dom/client';
function Football() {
const shoot = (a, b) => {
alert(b.type);
/*
'b' represents the React event that triggered the function.
In this case, the 'click' event
*/
}
return (
<button onClick={(event) => shoot("Goal!", event)}>Take the shot!</button>
);
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Football />);
=
=
class Car extends React.Component {
constructor(props) {
super(props);
}
render() {
return <h2>I am a {this.props.model}!</h2>;
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Car model="Mustang"/>);=
=
=
=
car.js
=
==
call funciton in another function
=
=
=
=
What started as a leak of shared Claude chats has turned into something much bigger — and much worse. The same thing is now happening with...