What do you want to save?
Add Code snippet
New code examples
-
Javascript 2021-10-17 19:22:03
react responsive screen size
const MyComponent = () => { // Declare a new state variable with the "useState" Hook const [width, setWidth] = React.useState(window.innerWidth); const breakpoint = 620; React.useEffect(() => { /* Inside of a "useEffect&q... Add solution -
Javascript 2021-09-18 04:57:03
how to connect socket in react js
connect to the socket server on component mount with useEffect save each new incoming message in the component's state. function App() { const [response, setResponse] = useState(""); useEffect(() => { const socket = socketIOClient(E... Add solution -
Javascript 2021-09-09 18:08:02
search bar idle time react js
How about a custom hook? import {useEffect, useRef, useState} from "react"; export default function useSearchInputState(searchHandler) { // to prevent calling the handler on component mount const didMountRef = useRef(false); const [s... Add solution -
Javascript 2021-09-06 12:04:02
stop playing music when page is closed react
import React, { useRef, useEffect } from 'react'; import waves from '../audio/waves.mp3'; const RockyCoast = (props) => { // the audio variable needs to be stored in a ref in order to access it across renders let audio = useRef(); // s... Add solution
Best helpers
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5