### App.js Source: https://18.react.dev/learn/installation An example React component demonstrating a simple greeting. ```javascript function Greeting({ name }) { return

Hello, {name}

; } export default function App() { return } ``` -------------------------------- ### Context provider setup Source: https://18.react.dev/reference/react/use Example showing how to wrap components with a context provider to pass context values ```javascript function MyPage() { return (
); } function Form() { // ... renders buttons inside ... } ``` -------------------------------- ### Example list before update Source: https://18.react.dev/learn/tutorial-tic-tac-toe An example of a list of tasks before any updates or reordering. ```html
  • Alexa: 7 tasks left
  • Ben: 5 tasks left
  • ``` -------------------------------- ### Basic preinit example Source: https://18.react.dev/reference/react-dom/preinit Simple example showing how to preinit an external script using the preinit function. ```javascript preinit("https://example.com/script.js", {as: "script"}); ``` -------------------------------- ### Example list after update Source: https://18.react.dev/learn/tutorial-tic-tac-toe An example of the same list after some items have been updated, reordered, and a new item inserted. ```html
  • Ben: 9 tasks left
  • Claudia: 8 tasks left
  • Alexa: 5 tasks left
  • ``` -------------------------------- ### Component Definition Example Source: https://18.react.dev/reference/rsc/use-client Example showing what a component definition looks like - a function that returns JSX. ```javascript // This is a definition of a component function MyComponent() { return

    My Component

    } ``` -------------------------------- ### Complete createElement example (App.js) Source: https://18.react.dev/reference/react/createElement A full `App.js` example demonstrating component definition and rendering using `createElement`. ```javascript import { createElement } from 'react'; function Greeting({ name }) { return createElement( 'h1', { className: 'greeting' }, 'Hello ', createElement('i', null, name), '. Welcome!' ); } export default function App() { return createElement( Greeting, { name: 'Taylor' } ); } ``` -------------------------------- ### Basic useActionState Example Source: https://18.react.dev/reference/react/useActionState Example demonstrating how to use useActionState with a simple increment action ```javascript import { useActionState } from "react"; async function increment(previousState, formData) { return previousState + 1; } function StatefulForm({}) { const [state, formAction] = useActionState(increment, 0); return ( {state}
    ) } ``` -------------------------------- ### Complete JSX example (App.js) Source: https://18.react.dev/reference/react/createElement A full `App.js` example demonstrating component definition and rendering using JSX. ```javascript function Greeting({ name }) { return (

    Hello {name}. Welcome!

    ); } export default function App() { return ; } ``` -------------------------------- ### Install Beta Release with npm Source: https://18.react.dev/learn/react-compiler Command to install the Beta release of babel-plugin-react-compiler and eslint-plugin-react-compiler using npm. ```bash npm install -D babel-plugin-react-compiler@beta eslint-plugin-react-compiler@beta ``` -------------------------------- ### Inline and external script examples Source: https://18.react.dev/reference/react-dom/components/script Examples showing both an inline script and an external script using the ``` -------------------------------- ### Importing and using memo Source: https://18.react.dev/reference/react/memo Demonstrates how to import memo and wrap a functional component. ```javascript import { memo } from 'react'; const SomeComponent = memo(function SomeComponent(props) { // ... }); ``` -------------------------------- ### Custom error handling with createRoot Source: https://18.react.dev/blog/2024/04/25/react-19-upgrade-guide Example demonstrating how to use `onUncaughtError` and `onCaughtError` options with `createRoot` for custom error reporting in React 19. ```javascript const root = createRoot(container, { onUncaughtError: (error, errorInfo) => { // ... log error report }, onCaughtError: (error, errorInfo) => { // ... log error report } }); ``` -------------------------------- ### React component composition example Source: https://18.react.dev/learn/your-first-component An example demonstrating how React components can be composed, ordered, and nested to build complex page layouts. ```jsx Docs ``` -------------------------------- ### useReducer Type Parameter Migration Source: https://18.react.dev/blog/2024/04/25/react-19-upgrade-guide Examples demonstrating the new best practice of not passing type arguments to useReducer and relying on contextual typing instead. ```typescript - useReducer>(reducer) + useReducer(reducer) ``` ```typescript - useReducer>(reducer) + useReducer(reducer) ``` ```typescript - useReducer>((state, action) => state) + useReducer((state: State, action: Action) => state) ``` ```typescript const reducer = (state: State, action: Action) => state; ``` -------------------------------- ### Handling keyboard events Source: https://18.react.dev/reference/react-dom/components/common This example shows some common keyboard events and when they fire. ```javascript export default function KeyboardExample() { return ( ); } ``` -------------------------------- ### Migrating Legacy Context to new contextType API Source: https://18.react.dev/blog/2024/04/25/react-19-upgrade-guide Example showing how to migrate from Legacy Context APIs (contextTypes, getChildContext) to the new contextType API. ```javascript // Before import PropTypes from 'prop-types'; class Parent extends React.Component { static childContextTypes = { foo: PropTypes.string.isRequired, }; getChildContext() { return { foo: 'bar' }; } render() { return ; } } class Child extends React.Component { static contextTypes = { foo: PropTypes.string.isRequired, }; render() { return
    {this.context.foo}
    ; } } ``` ```javascript // After const FooContext = React.createContext(); class Parent extends React.Component { render() { return ( ); } } class Child extends React.Component { static contextType = FooContext; render() { return
    {this.context}
    ; } } ``` -------------------------------- ### Complete example: Counters that update together Source: https://18.react.dev/learn A full, combined example demonstrating lifting state up to MyApp and passing it down to MyButton components for synchronized updates. ```javascript import { useState } from 'react'; export default function MyApp() { const [count, setCount] = useState(0); function handleClick() { setCount(count + 1); } return (

    Counters that update together

    ); } function MyButton({ count, onClick }) { return ( ); } ``` -------------------------------- ### Migrating propTypes and defaultProps for function components Source: https://18.react.dev/blog/2024/04/25/react-19-upgrade-guide Example showing how to migrate from propTypes and defaultProps to TypeScript interfaces and ES6 default parameters for function components. ```javascript // Before import PropTypes from 'prop-types'; function Heading({text}) { return

    {text}

    ; } Heading.propTypes = { text: PropTypes.string, }; Heading.defaultProps = { text: 'Hello, world!', }; ``` ```typescript // After interface Props { text?: string; } function Heading({text = 'Hello, world!'}: Props) { return

    {text}

    ; } ``` -------------------------------- ### Fixing implicit ref callback returns Source: https://18.react.dev/blog/2024/04/25/react-19-upgrade-guide Example demonstrating how to fix ref callback functions that implicitly return a value, which is now rejected by TypeScript due to ref cleanup functions. ```typescript -
    (instance = current)} /> +
    {instance = current}} /> ``` -------------------------------- ### Integrating data fetching with Suspense Source: https://18.react.dev/learn/start-a-new-react-project Example showing how to use Suspense to specify a loading state (like a skeleton placeholder) for different parts of your user interface directly in your React tree. ```jsx }> ```