### Install @react-three/flex Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Installs the @react-three/flex package using npm. This is the first step to integrate flexbox layouts into your react-three-fiber applications. ```bash npm install @react-three/flex ``` -------------------------------- ### Start Development Server Source: https://github.com/pmndrs/react-three-flex/blob/master/examples/README.md Runs the React application in development mode. It opens the app in the browser at http://localhost:3000 and enables hot reloading for edits. Lint errors are displayed in the console. ```bash yarn start ``` -------------------------------- ### Eject Configuration Source: https://github.com/pmndrs/react-three-flex/blob/master/examples/README.md A one-way operation that removes the single build dependency from the project. It copies all configuration files (webpack, Babel, ESLint, etc.) into the project, granting full control over customization. After ejecting, commands like `yarn start` will use the copied scripts. ```bash yarn eject ``` -------------------------------- ### Measuring Container with onReflow Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Demonstrates how to use the `onReflow` prop on the root `` component to get the calculated total width and height of the flex container. This is useful for synchronizing with DOM elements or modifying scrollable areas. ```jsx ...}> {/* ... */} ``` -------------------------------- ### Build for Production Source: https://github.com/pmndrs/react-three-flex/blob/master/examples/README.md Builds the React application for production, optimizing it for performance. The output is placed in the `build` folder, with minified code and hashed filenames for efficient deployment. ```bash yarn build ``` -------------------------------- ### Run Tests Source: https://github.com/pmndrs/react-three-flex/blob/master/examples/README.md Launches the test runner in interactive watch mode. This allows for continuous testing as code changes are made. Refer to the Create React App documentation for more details on running tests. ```bash yarn test ``` -------------------------------- ### Flex Component Usage Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Demonstrates the basic usage of the Flex component, including its core props like size, position, direction, plane, scaleFactor, and event handlers. It also shows how to include child Box components and pass through R3FlexProps. ```jsx {/* ... */} ``` -------------------------------- ### react-three-flex API Reference Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Provides a comprehensive overview of the props available for the Flex and Box components in react-three-flex. It details standard Flexbox properties inherited from Yoga, as well as custom props specific to the library. ```APIDOC Flex Component Props: size: [number, number, number] Description: Total size of the flex container. Default: [1, 1, 1] position: [number, number, number] Description: Position for the flex container in the scene. Default: [0, 0, 0] direction: "ltr" | "rtl" Description: Direction of the flex layout (left-to-right or right-to-left). Default: "ltr" plane: "xy" | "xz" | "yz" Description: Specifies the plane axes for the flex layout. Default: "xy" scaleFactor: number Description: An integer scale factor used for sizing calculations. Default: 100 onReflow: function Description: Callback function invoked whenever the layout is recalculated. Box Component Props: centerAnchor: boolean Description: If true, the inner content's position is relative to its center. Shared Props (from Yoga/Flexbox): Standard Flexbox properties such as 'alignItems', 'justifyContent', 'flexWrap', 'padding', 'margin', etc., are supported. Shorthands like 'pt' (paddingTop), 'align' (alignItems), 'justify' (justifyContent), and 'wrap' (flexWrap) are also available for convenience. ``` -------------------------------- ### Flexbox Props Shorthands Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Demonstrates the use of shorthand properties for common Flexbox props, such as padding, alignment, justification, and wrapping. These shorthands provide a more concise way to apply styles, mirroring CSS conventions. ```jsx // Flex with padding top set to 10, alignItems to 'center', justifyContent to 'space-around' and flexWrap to 'wrap' {/* ... */} ``` -------------------------------- ### Flex Container Sizing Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Demonstrates how to set the dimensions of a root flex container using the `size` prop. This is crucial for wrapping and responsiveness in 3D layouts. ```jsx {/* ... */} ``` -------------------------------- ### Margin and Padding Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Shows how to apply margins and padding to `` and `` components, similar to DOM elements, to control spacing and layout. ```jsx ``` -------------------------------- ### Basic Flexbox Layout with @react-three/flex Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Demonstrates a basic layout using the Flex and Box components from @react-three/flex. It centers two mesh objects within a flex container, utilizing justify and align properties. ```jsx import { Flex, Box } from '@react-three/flex' const Layout = () => ( ) ``` -------------------------------- ### Box Component Usage Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Illustrates the usage of the Box component, highlighting the centerAnchor prop for positioning content relative to its center and the ability to pass through R3FlexProps. It also shows how to render a mesh within the Box. ```jsx ``` -------------------------------- ### Controlling Element Sizing with useFlexSize Hook Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Demonstrates controlling element sizing using the `useFlexSize` hook. This hook provides the width and height of the flex item, enabling dynamic adjustments to child components. Note: The hook only works when the Box is outside the component using it. ```javascript function Inner() { const [width, height] = useFlexSize() return } function Outer() { return ( ) } ``` -------------------------------- ### Manual Reflow with useFrame Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Shows how to manually trigger a reflow using the `useReflow()` hook within the `useFrame` hook to update component properties, such as scale, and ensure the layout recalculates. ```jsx function AnimatedBox() { const ref = useRef() const reflow = useReflow() useFrame(({ clock }) => { ref.current.scale.x = 1 + Math.sin(clock.getElapsed()) reflow() }) return ( ``` -------------------------------- ### Nesting Flex Containers Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Illustrates how to create complex layouts by nesting `` components, allowing for hierarchical arrangement of elements. ```jsx ``` -------------------------------- ### Manual Reflow with useEffect Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Illustrates how to manually trigger a reflow using `useReflow()` within a `useEffect` hook, dependent on a state change, to ensure layout recalculation when external factors change. ```jsx function AnimatedBox() { const [state, setState] = useState(true) useInterval(() => setState((s) => !s), 1000) const reflow = useReflow() useEffect(reflow, [state]) return ( ``` -------------------------------- ### Using centerAnchor for Object Positioning Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Illustrates how to use the `centerAnchor` prop with the Box component. This prop is crucial when your THREE.js objects are centered by default, aligning their positioning with the flexbox layout's expectations. ```jsx ``` -------------------------------- ### Box Component with Function Children Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Shows an alternative way to use the Box component by passing a function as its children. This function receives the calculated width and height of the Box, allowing for dynamic rendering of content based on layout. ```jsx {(width, height) => } ``` -------------------------------- ### Controlling Element Sizing with Children Render Function Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Shows how to control element sizing within a flex container by using a children render function. This function receives the calculated width and height, allowing dynamic sizing of child elements like Planes. ```jsx {(width, height) => } ``` -------------------------------- ### Axis Orientation Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Explains how to specify the 2D plane for flex layout calculations using the `plane` prop. The default is 'xy', but 'yz' and 'xz' are also supported. The `size` prop is interpreted relative to the chosen axes. ```jsx {/* ... */} ``` -------------------------------- ### Triggering Reflow with useInterval Source: https://github.com/pmndrs/react-three-flex/blob/master/README.md Demonstrates how a state change within a component that renders a Box triggers a reflow. This is contrasted with a scenario where the Box is rendered outside the component, which does not trigger a reflow. ```jsx function AnimatedBox() { // Since is inside the component, setting the state will rerender it, thus causing a reflow. // ⚠️ If were outside this component, this would NOT cause a reflow! const [state, setState] = useState(true) useInterval(() => setState((s) => !s), 1000) return ( ``` ```jsx function AnimatedBox() { // ⚠️ Setting state does not rerender since it's in the parent // ‼️ No Reflow!! const [state, setState] = useState(true) useInterval(() => setState((s) => !s), 1000) return ( ) } function Layout() { return ( ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.