What do you want to save?
Add Code snippet
New code examples
-
Javascript 2022-03-27 07:10:04
useffect compare previous value to current
//Custom Hook function usePrevious(value) { const ref = useRef(); useEffect(() => { ref.current = value; }); return ref.current; } // Use it in useEffect const Component = (props) => { const {receiveAmount, sendAmount } = props ... Add solution -
Javascript 2022-03-16 18:05:04
react useeffect common dependency
import React, { useState, useRef, useEffect } from "react"; function EffectsDemoNoDependency() { const [title, setTitle] = useState("default title"); const titleRef = useRef(); useEffect(() => { console.log("useEffect... Add solution -
Javascript 2021-09-25 11:00:03
usePrevious
import { useState, useEffect, useRef } from "react"; // Usage function App() { // State value and setter for our example const [count, setCount] = useState(0); // Get the previous value (was passed into hook on last render) const prevC... Add solution -
Javascript 2021-09-21 14:13:03
useref material ui
// Using the useRef() hook. Only possible when you're using a function component. const App = () => { const textRef = useRef(); const showRefContent = () => { console.log(textRef.current.value); }; return ( <div className="Ap... 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
Ranking is empty