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 React, { useImperativeHandle, useRef } from 'react'; | |
| type Props = { | |
| open: boolean; | |
| onClose: () => void; | |
| ref: HTMLDivElement | any; | |
| }; | |
| const CustomModal = ({ open, onClose, ref }: Props) => { | |
| const closeRef = useRef<HTMLButtonElement>(null); | |
| const confirmRef = useRef<HTMLButtonElement>(null); |
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 React from 'react'; | |
| type Props = { | |
| open: boolean; | |
| onClose: () => void; | |
| ref: HTMLDivElement | any; | |
| }; | |
| const CustomModal = ({ open, onClose, ref }: Props) => { | |
| if (!open) return null; | |
| return ( |
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 React, { useState, useRef } from 'react'; | |
| import CustomModal from './custom-modal'; | |
| const Modal = () => { | |
| const [open, setOpen] = useState<boolean>(false); | |
| const ref = useRef<HTMLDivElement>(null); | |
| const onClose = (): void => { | |
| setOpen(false); | |
| }; |
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 React, { useImperativeHandle } from 'react'; | |
| const CustomField = (props: any, ref: HTMLInputElement | any) => { | |
| useImperativeHandle( | |
| ref, | |
| () => { | |
| return { alertValue: () => alert(props.value) }; | |
| }, | |
| [props.value] | |
| ); |
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 React, { useState, useRef } from 'react'; | |
| import CustomField from './custom-field'; | |
| const Form = () => { | |
| const [value, setValue] = useState<string>(''); | |
| const ref: HTMLInputElement | any = useRef<HTMLInputElement>(null); | |
| return ( | |
| <React.Fragment> | |
| <CustomField |
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 React, { useImperativeHandle } from 'react'; | |
| const CustomField = (props: any, ref: HTMLInputElement | any) => { | |
| useImperativeHandle(ref, () => { | |
| return { alertHi: () => alert('Hola') }; | |
| }); | |
| return <input style={{ backgroundColor: 'red' }} {...props} />; | |
| }; | |
| export default React.forwardRef(CustomField); |
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 React from 'react'; | |
| const CustomField = (props: any, ref: HTMLInputElement | any) => { | |
| return <input ref={ref} style={{ backgroundColor: 'red' }} {...props} />; | |
| }; | |
| export default React.forwardRef(CustomField); |
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 React, { useState, useRef } from 'react'; | |
| import CustomField from './custom-field'; | |
| const Form = () => { | |
| const [value, setValue] = useState<string>(''); | |
| const ref = useRef<HTMLInputElement>(null); | |
| return ( | |
| <React.Fragment> | |
| <CustomField |
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 React, { useState, useRef } from 'react'; | |
| const Form = () => { | |
| const [value, setValue] = useState<string>(''); | |
| const ref = useRef<HTMLInputElement>(null); | |
| return ( | |
| <React.Fragment> | |
| <input | |
| type='text' |
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 React, { useId } from 'react'; | |
| const Login = () => { | |
| const id = useId(); | |
| return ( | |
| <React.Fragment> | |
| <div> | |
| <label htmlFor={`${id}-email`}>Email</label> | |
| <input id={`${id}-email`} type='email' /> | |
| </div> |