What do you want to save?
Add Code snippet
New code examples
-
Javascript 2021-10-30 01:43:13
react how to scroll to element
import React, { useRef } from 'react' const scrollToRef = (ref) => window.scrollTo(0, ref.current.offsetTop) // General scroll to element function const ScrollDemo = () => { const myRef = useRef(null) const executeScroll = () => scrol... Add solution -
Other 2021-10-20 07:32:03
Detect click outside React component
import React, { useRef, useEffect } from "react"; /** * Hook that alerts clicks outside of the passed ref */ function useOutsideAlerter(ref) { useEffect(() => { /** * Alert if clicked on outside of element */ ... Add solution -
Javascript 2021-10-19 20:44:05
useReducer example
/* A common use case is to access a child imperatively: */ function TextInputWithFocusButton() { const inputEl = useRef(null); const onButtonClick = () => { // `current` points to the mounted text input element inputEl.current.focus(); ... Add solution -
CSS 2021-10-18 13:46:07
get input value with useref
import React, { Component, useRef } from 'react' import { render } from 'react-dom' import InputField from './inputfield' import './style.css' function App () { const nameForm = useRef(null) const handleClickEvent = () => { const form = na... Add solution -
Javascript 2021-10-13 17:32:03
popup model in tailwind css
/* This example requires Tailwind CSS v2.0+ */ import { Fragment, useRef, useState } from 'react' import { Dialog, Transition } from '@headlessui/react' import { ExclamationIcon } from '@heroicons/react/outline' export default function Example() { cons... Add solution -
Javascript 2021-10-03 20:32:07
useref in functional component
/* A common use case is to access a child imperatively: */ function TextInputWithFocusButton() { const inputEl = useRef(null); const onButtonClick = () => { // `current` points to the mounted text input element inputEl.current.focus(); ... Add solution