<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Darik Mohammed on Medium]]></title>
        <description><![CDATA[Stories by Darik Mohammed on Medium]]></description>
        <link>https://medium.com/@r.m.darik?source=rss-5a32d2e097cd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tFT8z-k_w78PqoMpTXPQMw.jpeg</url>
            <title>Stories by Darik Mohammed on Medium</title>
            <link>https://medium.com/@r.m.darik?source=rss-5a32d2e097cd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 22:58:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@r.m.darik/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[React Props Drilling]]></title>
            <link>https://medium.com/@r.m.darik/react-props-drilling-c2dfdacb6b7?source=rss-5a32d2e097cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2dfdacb6b7</guid>
            <category><![CDATA[managing-props-in-react]]></category>
            <category><![CDATA[react-components]]></category>
            <category><![CDATA[react-prop-drilling]]></category>
            <category><![CDATA[avoiding-prop-spaghetti]]></category>
            <category><![CDATA[efficient-prop-transfer]]></category>
            <dc:creator><![CDATA[Darik Mohammed]]></dc:creator>
            <pubDate>Wed, 08 Feb 2023 17:48:12 GMT</pubDate>
            <atom:updated>2023-02-08T17:48:12.269Z</atom:updated>
            <content:encoded><![CDATA[<p>React is a fantastic tool for building user interfaces, and one of its key strengths is the ability to pass data from a parent component to its child components through props.</p><p>When working with React, there will be times when we need to pass data or state from a top-level component to a component that is nested deep within our application. To accomplish this, we often use a technique known as “prop drilling.” This involves moving the data from its source to its final destination by passing it through a series of intermediate components, each passing it along as a prop.</p><h3>Basics of Props Drilling</h3><p>Let’s start by defining what props drilling is. Essentially, it’s the process of passing data from a parent component to its child components through props. Let us look at the example below!</p><pre>import { useState } from &quot;react&quot;;<br><br>export default function App() {<br>  const [firstName, setFirstName] = useState(&quot;Darik&quot;);<br>  const [lastName, setLastName] = useState(&quot;Mohammed&quot;);<br>  return (<br>    &lt;&gt;<br>      &lt;User name={firstName} setName={setFirstName} /&gt;<br>      &lt;User name={lastName} setName={setLastName} /&gt;<br>    &lt;/&gt;<br>  );<br>}<br><br>function User({ name, setName }) {<br>  return (<br>    &lt;div&gt;<br>      name: {name}<br>      &lt;NameEditor name={name} setName={setName} /&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>function NameEditor({ name, setName }) {<br>  return (<br>    &lt;div&gt;<br>      &lt;input<br>        type=&quot;text&quot;<br>        value={name}<br>        onChange={(e) =&gt; setName(e.target.value)}<br>      /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>In this example, we see that the &lt;User /&gt; component isn’t using the setName prop. Instead, it&#39;s handing it off to its child component, the &lt;NameEditor /&gt;. This is causing what&#39;s known as &quot;prop drilling.&quot; Prop drilling happens when data or state needs to be passed from a higher-level component to a deeply nested component, and the process often involves passing the data through multiple intermediate components. In this scenario, the &lt;User /&gt; component is passing the setName prop down to its child component, but it&#39;s not using it. This type of delegation can help keep components organized and focused, but it can also lead to situations of prop drilling if not handled properly.</p><h3>Solving Props Drilling Challenges</h3><p><strong>Component Composition</strong></p><p>If you want to remove the prop drilling in the code, the component composition is one solution. This technique involves the composition of the components that surround the existing ones and only sending the necessary props down. By doing this, you can simplify your code and make it easier to read and maintain. Here’s an example of how you can use component composition to refactor the code:</p><pre>import { useState } from &quot;react&quot;;<br><br>export default function App() {<br>  const [firstName, setFirstName] = useState(&quot;Darik&quot;);<br>  const [lastName, setLastName] = useState(&quot;Mohammed&quot;);<br>  return (<br>    &lt;&gt;<br>      &lt;User name={firstName}&gt;<br>        &lt;NameEditor name={firstName} setName={setFirstName} /&gt;<br>      &lt;/User&gt;<br>      &lt;User name={lastName}&gt;<br>        &lt;NameEditor name={lastName} setName={setLastName} /&gt;<br>      &lt;/User&gt;<br>    &lt;/&gt;<br>  );<br>}<br><br>function User({ name, children }) {<br>  return (<br>    &lt;div&gt;<br>      Username: {name}<br>      {children}<br>    &lt;/div&gt;<br>  );<br>}<br><br>function NameEditor({ name, setName }) {<br>  return (<br>    &lt;div&gt;<br>      &lt;input<br>        type=&quot;text&quot;<br>        value={name}<br>        onChange={(e) =&gt; setName(e.target.value)}<br>      /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>The revised code presents the &lt;User /&gt; component as a container, which takes in the name and children as props. On the other hand, the NameEditor remains untouched. This change effectively eliminates the issue of props drilling.</p><p><strong>Using context API</strong></p><p>The use of the Context API is a well-regarded solution for tackling the issue of props drilling. While it’s a popular method, it’s not necessarily the best fit for every situation. The key is to weigh the pros and cons and determine what approach works best for your specific project needs.</p><pre>import React, { createContext, useState } from &quot;react&quot;;<br><br>export const NameContext = createContext(null);<br><br>export default function App() {<br>  const [firstName, setFirstName] = useState(&quot;Darik&quot;);<br>  const [lastName, setLastName] = useState(&quot;Mohammed&quot;);<br>  return (<br>    &lt;&gt;<br>      &lt;NameContext.Provider value={{ name: firstName, setName: setFirstName }}&gt;<br>        &lt;User /&gt;<br>      &lt;/NameContext.Provider&gt;<br>      &lt;NameContext.Provider value={{ name: lastName, setName: setLastName }}&gt;<br>        &lt;User /&gt;<br>      &lt;/NameContext.Provider&gt;<br>    &lt;/&gt;<br>  );<br>}<br><br>function User() {<br>  const { name } = React.useContext(NameContext);<br>  return (<br>    &lt;div&gt;<br>      Username: {name}<br>      &lt;NameEditor /&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>function NameEditor() {<br>  const { name, setName } = React.useContext(NameContext);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;input<br>        type=&quot;text&quot;<br>        value={name}<br>        onChange={(e) =&gt; setName(e.target.value)}<br>      /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>In this example, we put into play the createContext function from React to set up a NameContext. The state of {name, setName} is provided by a provider, which is then shared and accessible to both the &lt;User /&gt; and &lt;NameEditor /&gt; components through the use of the useContext hook.</p><p>There are other solutions to tackle props drilling as well, which we won’t delve into in this article. However, for those interested in exploring other options, quick research should provide you with more information.</p><h3>Conclusion</h3><p>Props drilling in React can be a bit of a headache, especially as your application becomes larger. However, by utilizing the techniques we’ve discussed and others, you can effectively handle and manage the flow of props in your React applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2dfdacb6b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React3Fiber and React!]]></title>
            <link>https://medium.com/@r.m.darik/react3fiber-and-react-f68a493512fa?source=rss-5a32d2e097cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/f68a493512fa</guid>
            <category><![CDATA[react-three-fiber]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-three-drei]]></category>
            <category><![CDATA[threejs]]></category>
            <dc:creator><![CDATA[Darik Mohammed]]></dc:creator>
            <pubDate>Sun, 11 Dec 2022 21:36:36 GMT</pubDate>
            <atom:updated>2022-12-11T21:36:36.072Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever thought about creating a stunning 3d website? You can create a superb WebGL website using Three js. Three js provides many features for drawing 3d scenes in your browser.</p><p>I’m not going into detail about Three js and WebGL in this article, to know more about visit their official website <a href="https://threejs.org/">https://threejs.org/</a> and have fun!</p><p>In this article, I will go through how to use React3Fiber which is React renderer for three js, and everything that works in Three js works here as well. We will be building a React application with a 3d scene.</p><p>This is going to be our final output after going through the article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*0ax2hSC-Uhoj2szYeprw8g.gif" /></figure><p><strong>Creating a React Application</strong></p><p>To begin, open a terminal and create a react application.</p><pre>npx create-react-app r3f-react</pre><p>Include Material UI for Icons, in the terminal</p><pre>npm install @mui/material @emotion/react @emotion/styled<br>npm install @mui/icons-material</pre><p>For styling I’m going to use Tailwind CSS, let us include tailwind CSS in our react application.</p><p>In the terminal,</p><pre>cd r3f-react/<br>npm install -D tailwindcss postcss autoprefixer<br>npx tailwindcss init -p</pre><p>In the tailwind.config.js add the path to all of your template files</p><pre>content: [<br>    &quot;./src/**/*.{js,jsx,ts,tsx}&quot;,<br>  ],</pre><p>Go to the index.css file located in the ./src folder and add tailwind directives</p><pre>@tailwind base;<br>@tailwind components;<br>@tailwind utilities;</pre><p>Now we are ready to use tailwind CSS in our react app.</p><p>Next up, install the React3Fiber.</p><p>In the terminal,</p><pre>npm install three @types/three @react-three/fiber</pre><p><strong>Now let us build our app 🤓</strong></p><p>We can start off by refactoring the default react application, in the app.js file we can remove the logo and return function so that it looks like this.</p><pre>function App() {<br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;h1&gt;React3Fiber - React&lt;/h1&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>While I use Tailwind CSS to style my application I usually delete the app.css file. Now we can check if everything is working as expected, Go to the terminal.</p><pre>npm start</pre><p>Your local host should start working without no errors.</p><p><strong>Building the NavBar</strong></p><p>Since this article is more about React3Fiber I won’t be going through the details of react-router and explaining the styling.</p><p>We can start off by creating a component Nav.js file for our navigation menu in our ./src/components</p><p>This is what our file is going to look like.</p><pre>import React from &#39;react&#39;;<br>import SearchIcon from &#39;@mui/icons-material/Search&#39;;<br>import ShoppingCartIcon from &#39;@mui/icons-material/ShoppingCart&#39;;<br><br>function Nav() {<br>  return (<br>    &lt;div className=&quot;flex justify-between items-center py-8&quot;&gt;<br>      &lt;h3 className=&quot; text-2xl font-semibold&quot;&gt;<br>        &lt;span className=&quot; text-orange-500&quot;&gt;Go&lt;/span&gt; Shop<br>      &lt;/h3&gt;<br>      &lt;div className=&quot;flex items-center&quot;&gt;<br>        &lt;ul className=&quot;flex items-center gap-4 text-lg&quot;&gt;<br>          &lt;li&gt;Home&lt;/li&gt;<br>          &lt;li&gt;About&lt;/li&gt;<br>          &lt;li&gt;Product&lt;/li&gt;<br>          &lt;li&gt;Shop&lt;/li&gt;<br>          &lt;li&gt;Contact&lt;/li&gt;<br>        &lt;/ul&gt;<br>      &lt;/div&gt;<br>      &lt;div className=&quot;flex items-center&quot;&gt;<br>        &lt;ul className=&quot;flex items-center gap-4&quot;&gt;<br>          &lt;li&gt;<br>            &lt;SearchIcon /&gt;<br>          &lt;/li&gt;<br>          &lt;li&gt;<br>            &lt;ShoppingCartIcon /&gt;<br>          &lt;/li&gt;<br>          &lt;li className=&quot; bg-sky-500 text-white rounded px-4 py-2&quot;&gt;<br>            Get Started<br>          &lt;/li&gt;<br>        &lt;/ul&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Nav;</pre><p><strong>Note</strong>: Don’t forget to add your component to your app.js file</p><pre>import Nav from &#39;./components/Nav&#39;;<br><br>function App() {<br>  return (<br>    &lt;div className=&quot;px-32&quot;&gt;<br>      &lt;Nav /&gt;<br>      &lt;h1&gt;React3Fiber - React&lt;/h1&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>This is how our app is looking so far.</p><figure><img alt="NavBar of our app" src="https://cdn-images-1.medium.com/max/1024/1*tTKLbr-u7-vQJZMJKiRf5A.png" /></figure><p><strong>The body section</strong></p><p>Now that we have finished working on the nav bar we can start working on the body.</p><p>We can create another component for our body Body.js in .src/components/</p><pre>import React from &#39;react&#39;;<br><br>import ShoppingCartIcon from &#39;@mui/icons-material/ShoppingCart&#39;;<br>import NavigateNextIcon from &#39;@mui/icons-material/NavigateNext&#39;;<br><br>function Body() {<br>  return (<br>    &lt;div className=&quot;grid grid-cols-2 gap-2 mt-8&quot;&gt;<br>      &lt;div className=&quot;flex flex-col gap-4&quot;&gt;<br>        &lt;h1 className=&quot; text-8xl font-bold&quot;&gt;Our Best Collection for You! &lt;/h1&gt;<br>        &lt;p&gt;<br>          The style of watches available to customers are endless and profits<br>          also endless.<br>        &lt;/p&gt;<br>        &lt;div className=&quot; flex gap-4&quot;&gt;<br>          &lt;button className=&quot;text-white bg-orange-500 px-4 py-2 rounded&quot;&gt;<br>            &lt;ShoppingCartIcon /&gt; Add to Cart<br>          &lt;/button&gt;<br><br>          &lt;button className=&quot;hover:border-orange-500 hover:border-solid border-2 rounded px-4 py-1 border-none&quot;&gt;<br>            More Info &lt;NavigateNextIcon /&gt;<br>          &lt;/button&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>      &lt;div className=&quot;&quot; id=&quot;watch-canvas-container&quot;&gt;&lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Body;</pre><p><strong>Reminder:</strong> Don’t forget to include it in your app.js file.</p><p>This is our app so far</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*McCKRAWIL9ZNZ4TTyzjjsA.png" /></figure><h3><strong>React3Fiber</strong></h3><p>The fun part starts now. Until now we have been running the regular react js code that we all know.</p><p>We can start by importing &lt;Canvas /&gt; from @react-three/fiber. The canvas component will do important setup work behind the scene by creating the camera and the scene which are the basic building block for rendering.</p><pre>import React from &#39;react&#39;;<br><br>import ShoppingCartIcon from &#39;@mui/icons-material/ShoppingCart&#39;;<br>import NavigateNextIcon from &#39;@mui/icons-material/NavigateNext&#39;;<br>import { Canvas } from &#39;@react-three/fiber&#39;;<br><br>function Body() {<br>  return (<br>    &lt;div className=&quot;grid grid-cols-2 gap-2 mt-8&quot;&gt;<br>      &lt;div className=&quot;flex flex-col gap-4&quot;&gt;<br>        &lt;h1 className=&quot; text-8xl font-bold&quot;&gt;Our Best Collection for You! &lt;/h1&gt;<br>        &lt;p&gt;<br>          The style of watches available to customers are endless and profits<br>          also endless.<br>        &lt;/p&gt;<br>        &lt;div className=&quot; flex gap-4&quot;&gt;<br>          &lt;button className=&quot;text-white bg-orange-500 px-4 py-2 rounded&quot;&gt;<br>            &lt;ShoppingCartIcon /&gt; Add to Cart<br>          &lt;/button&gt;<br><br>          &lt;button className=&quot;hover:border-orange-500 hover:border-solid border-2 rounded px-4 py-1 border-none&quot;&gt;<br>            More Info &lt;NavigateNextIcon /&gt;<br>          &lt;/button&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>      &lt;div className=&quot;&quot; id=&quot;watch-canvas-container&quot;&gt;<br>        &lt;Canvas&gt;&lt;/Canvas&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Body;</pre><p>Our body component is going to look like this after adding the Canvas to our component. But we can not see anything yet, in order to see something in our scene let us add Box geometry with a Basic Material inside our canvas.</p><pre>&lt;Canvas&gt;<br>  &lt;mesh scale={4}&gt;<br>    &lt;boxGeometry /&gt;<br>    &lt;meshBasicMaterial color={&#39;red&#39;} /&gt;<br>  &lt;/mesh&gt;<br>&lt;/Canvas&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*91_gtAZoSBEg04uxeW1UwA.png" /></figure><p>Now a red box appears in our scene 👍.</p><p>We can not look around through our box, Orbitcontrols will allow a camera to orbit around a target. Let us add it</p><p>We can see that React3Fiber had already made Threejs simple. Thanks to React for making things reusable, R3F took advantage of that and developers are creating helpers ready to be used in your R3F application. These helpers can be used as a component and some as hooks and you can find most of them regrouped in Drei.</p><p>Now we can add Drei to our app, in the terminal</p><pre>npm install @react-three/drei</pre><p>Import OrbitControls in our component and include it in our canvas.</p><pre>import {<br>  OrbitControls<br>} from &#39;@react-three/drei&#39;;</pre><pre>&lt;Canvas&gt;<br>&lt;OrbitControls /&gt;<br>  &lt;mesh scale={4}&gt;<br>    &lt;boxGeometry /&gt;<br>    &lt;meshBasicMaterial color={&#39;red&#39;} /&gt;<br>  &lt;/mesh&gt;<br>&lt;/Canvas&gt;<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*HWh4CKOKYzH7fQN-lOlAAA.gif" /></figure><p>Yey, We can now rotate through our scene.</p><p><strong>Models</strong></p><p>First, we need a model and through time, many 3D model formats have been used. We have access to hundreds of model formats: <a href="https://en.wikipedia.org/wiki/List_of_file_formats#3D_graphics">https://en.wikipedia.org/wiki/List_of_file_formats#3D_graphics</a>.</p><p>We are going to work with GLTF format but this step works for others file formats too.</p><p><strong>Note: Don’t forget to check the license of the models you are using and make sure you have access to use them for commercial.</strong></p><p>I will be using Apple Watch Series 7 — Free Watch-Face SDC™️ created by bharathsrk13.</p><p>You can download it at: <a href="https://sketchfab.com/3d-models/apple-watch-series-7-free-watch-face-sdctm-cf15ecbf159f42a28df5e56bdfa666bb">https://sketchfab.com/3d-models/apple-watch-series-7-free-watch-face-sdctm-cf15ecbf159f42a28df5e56bdfa666bb</a></p><p>After downloading the gltf file put it in the ./public folder</p><p><strong>IMPORTING OUR MODEL TO THE SCENE</strong></p><p>We will be using Drei helper for simplicity but there are other ways to import models to a scene I found useGLTF helper from Drei simple.</p><p>You can future read about importing a model here: <a href="https://docs.pmnd.rs/react-three-fiber/tutorials/loading-models">https://docs.pmnd.rs/react-three-fiber/tutorials/loading-models</a></p><p>We can start by creating a component for our watch inside the ./src/components folder.</p><p>This is what our file is going to look like.</p><pre>import { useGLTF } from &#39;@react-three/drei&#39;;<br><br>function Watch(props) {<br>  const model = useGLTF(&#39;./watch.glb&#39;);<br>  return (<br>    &lt;&gt;<br>      &lt;primitive object={model.scene} {...props} /&gt;;<br>    &lt;/&gt;<br>  );<br>}<br><br>export default Watch;</pre><p><strong>What is happening?</strong></p><p>First, we import the helper useGLTF and load our mode by providing our model location. Lastly, we can display our model in our scene using primitive.</p><p><strong>Note: Don’t forget to call this component inside our canvas.</strong></p><p>You can see that we have removed our box from the scene and added the watch inside our scene</p><pre>&lt;Canvas&gt;<br>  &lt;OrbitControls /&gt;<br>  &lt;Watch scale={70} rotation-x={Math.PI / 7}/&gt;<br>&lt;/Canvas&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1UAJYMh5U2z3JFaOUg0FKQ.png" /></figure><p>You may be wondering why our scene is black. We have no light in our scene and let us add one now.</p><pre>&lt;Canvas&gt;<br>  &lt;OrbitControls /&gt;<br>  &lt;directionalLight castShadow position={[1, 2, 3]} intensity={1.5} /&gt;<br>  &lt;ambientLight intensity={1} /&gt;<br>  &lt;Watch scale={70} /&gt;<br>&lt;/Canvas&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-IE0OpDVLl5zjKOJo2dsCQ.png" /></figure><p>Now our scene is live. 🎉</p><h3><strong>Going Further</strong></h3><p>We can go further and create shadow, the environmental helper to create a reactive, dynamic environment map effect and also update our orbit control.</p><p>I am not going into detail but you can further investigate the code and tweak it to your preference.</p><p>./src/components/Body.js</p><pre>import React from &#39;react&#39;;<br>import {<br>  OrbitControls,<br>  ContactShadows,<br>  Environment,<br>  PresentationControls,<br>} from &#39;@react-three/drei&#39;;<br><br>import ShoppingCartIcon from &#39;@mui/icons-material/ShoppingCart&#39;;<br>import NavigateNextIcon from &#39;@mui/icons-material/NavigateNext&#39;;<br>import { Canvas } from &#39;@react-three/fiber&#39;;<br>import Watch from &#39;./Watch&#39;;<br><br>function Body() {<br>  return (<br>    &lt;div className=&quot;grid grid-cols-2 gap-2 mt-8&quot;&gt;<br>      &lt;div className=&quot;flex flex-col gap-4&quot;&gt;<br>        &lt;h1 className=&quot; text-8xl font-bold&quot;&gt;Our Best Collection for You! &lt;/h1&gt;<br>        &lt;p&gt;<br>          The style of watches available to customers are endless and profits<br>          also endless.<br>        &lt;/p&gt;<br>        &lt;div className=&quot; flex gap-4&quot;&gt;<br>          &lt;button className=&quot;text-white bg-orange-500 px-4 py-2 rounded&quot;&gt;<br>            &lt;ShoppingCartIcon /&gt; Add to Cart<br>          &lt;/button&gt;<br><br>          &lt;button className=&quot;hover:border-orange-500 hover:border-solid border-2 rounded px-4 py-1 border-none&quot;&gt;<br>            More Info &lt;NavigateNextIcon /&gt;<br>          &lt;/button&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>      &lt;div className=&quot;&quot; id=&quot;watch-canvas-container&quot;&gt;<br>        &lt;Canvas&gt;<br>          {/* &lt;OrbitControls /&gt; */}<br>          {/* &lt;directionalLight castShadow position={[1, 2, 3]} intensity={1.5} /&gt;<br>          &lt;ambientLight intensity={1} /&gt; */}<br><br>          &lt;PresentationControls<br>            global<br>            config={{ mass: 2, tension: 500 }}<br>            snap={{ mass: 4, tension: 1500 }}<br>            rotation={[0, 0.3, 0]}<br>            polar={[-Math.PI / 3, Math.PI / 3]}<br>            azimuth={[-Math.PI / 1.4, Math.PI / 2]}<br>          &gt;<br>            &lt;Watch scale={60} rotation-x={Math.PI / 7} /&gt;<br>          &lt;/PresentationControls&gt;<br><br>          &lt;ContactShadows<br>            position={[0, -1.4, 0]}<br>            opacity={0.75}<br>            scale={10}<br>            blur={2.5}<br>            far={4}<br>          /&gt;<br>          &lt;Environment preset=&quot;city&quot; /&gt;<br>        &lt;/Canvas&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Body;</pre><p>./src/components/Watch.js</p><pre>import React, { useRef } from &#39;react&#39;;<br>import { useFrame } from &#39;@react-three/fiber&#39;;<br>import { useGLTF } from &#39;@react-three/drei&#39;;<br><br>function Watch(props) {<br>  const model = useGLTF(&#39;./watch.glb&#39;);<br>  const ref = useRef();<br>  useFrame((state) =&gt; {<br>    const t = state.clock.getElapsedTime();<br>    ref.current.rotation.y = Math.sin(t / 4) / 8;<br>    ref.current.rotation.z = (1 + Math.sin(t / 1.5)) / 20;<br>    ref.current.position.y = (1 + Math.sin(t / 1.5)) / 10;<br>  });<br><br>  return (<br>    &lt;&gt;<br>      &lt;primitive object={model.scene} ref={ref} {...props} /&gt;;<br>    &lt;/&gt;<br>  );<br>}<br><br>export default Watch;</pre><p><strong>The End</strong></p><p>In this article, we have seen how to import 3d models in React using React3Fiber. I hope you will find this useful. A fully working version is available on GitHub if you are interested in checking it out.</p><p><a href="https://github.com/darikmohammed/go-shop-r3f">https://github.com/darikmohammed/go-shop-r3f</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f68a493512fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>