Props
Video Lecture
Section | Video Links | |
---|---|---|
Props |
Description
Props (a.k.a. properties) are used in React to pass in attributes to your components when you declare them in the JSX.
Our Box from the last lesson is our component that returns a JSX.Element
describing a THREE.Mesh
.
But we cannot modify any of its properties when we create it, so if we create 2 or more, then they will just be placed in the scene on top of each other in the same position.
Instead, we can add props
that we will use to further initialize them with a position when we declare them in the JSX.
./src/Box.jsx
1 2 3 4 5 6 7 8 |
|
./src/App.jsx
1 2 3 4 5 6 7 8 9 10 11 |
|
Note that React will re-render any component instances whenever a change is made to its state or props.
Working Example
Useful Links
Components and Props | reactjs.org | sbedit.net |
Spread Syntax | developer.mozilla.org | |
Destructuring Assignment | developer.mozilla.org | |
THREE.Mesh | threejs.org | |
THREE.Object3D | threejs.org | sbcode.net |
GitHub Branch
git clone https://github.com/Sean-Bradley/React-Three-Fiber-Boilerplate.git
cd React-Three-Fiber-Boilerplate
git checkout props
npm install
npm start