Skip to content

Instantly share code, notes, and snippets.

View cupid-dust's full-sized avatar

Ahsan Ali Mansoor cupid-dust

  • Spadasoft
  • Lahore
View GitHub Profile
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);
import React from 'react';
type Props = {
open: boolean;
onClose: () => void;
ref: HTMLDivElement | any;
};
const CustomModal = ({ open, onClose, ref }: Props) => {
if (!open) return null;
return (
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);
};
import React, { useImperativeHandle } from 'react';
const CustomField = (props: any, ref: HTMLInputElement | any) => {
useImperativeHandle(
ref,
() => {
return { alertValue: () => alert(props.value) };
},
[props.value]
);
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
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);
import React from 'react';
const CustomField = (props: any, ref: HTMLInputElement | any) => {
return <input ref={ref} style={{ backgroundColor: 'red' }} {...props} />;
};
export default React.forwardRef(CustomField);
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
import React, { useState, useRef } from 'react';
const Form = () => {
const [value, setValue] = useState<string>('');
const ref = useRef<HTMLInputElement>(null);
return (
<React.Fragment>
<input
type='text'
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>