This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Pub/Sub in React Context | |
| While React Context is a great way to share data between components, it doesn't inherently implement the Pub/Sub pattern. However, you can combine the two to create a Pub/Sub system within your React application. | |
| Here's a simple implementation: | |
| ```js | |
| import React, { createContext, useContext, useState, useEffect } from 'react'; | |
| const EventContext = createContext(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect, useRef, useState } from 'react'; | |
| import { useFrame, useThree } from '@react-three/fiber'; | |
| import { MapControls, OrthographicCamera, PerspectiveCamera } from '@react-three/drei'; | |
| import type { OrbitControls as OrbitControlsImpl } from 'three-stdlib'; | |
| export function Camera() { | |
| const [oldType, setOldType] = useState('PerspectiveCamera'); | |
| const [coords, setCoords] = useState({ x: 0, y: 0 }); | |
| const gl = useThree((state) => state.gl); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect, useRef } from 'react'; | |
| export function App() { | |
| // Use a ref to access the Canvas | |
| const canvasRef = useRef<HTMLCanvasElement>(null); | |
| // Use a ref to keep access to the Canvas Context | |
| const canvasCtxRef = useRef<CanvasRenderingContext2D | null>(null); | |
| const draw = (ctx: CanvasRenderingContext2D, frameCount: number) => { |