Ugrás a tartalomra

Code Mosh React 18 Beginners Fco Apr 2026

function MovieIdea() return ( <div> <h2>Inception</h2> <p>A dream within a dream</p> </div> );

return ( <button onClick=() => setLikes(likes + 1)> 👍 likes </button> );

<MovieIdea title="Interstellar" description="Love across time and space" /> import useState from 'react'; function LikeButton() const [likes, setLikes] = useState(0); code mosh react 18 beginners fco

useEffect(() => fetch('https://movie-quote-api.com/random') .then(res => res.json()) .then(data => setFact(data.quote)); , []); // empty array = run once

✅ React 18 automatically batches multiple setLikes calls. function MovieList() const movies = [ id: 1, title: 'The Matrix' , id: 2, title: 'Gladiator' ]; return ( <ul> movies.map(movie => ( <li key=movie.id>movie.title</li> )) </ul> ); export default MovieIdea;

import MovieIdea from './MovieIdea'; function App() return ( <div> <h1>My Movie Ideas</h1> <MovieIdea /> </div> );

React 18’s strict mode mounts/unmounts/mounts in dev – be aware. createRoot (instead of ReactDOM.render) index.js export default MovieIdea

If two components need same data → move state to closest common parent.

export default MovieIdea;