Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dandelionadia/82e2ac961abfecc8b62ef1084e90e5ec to your computer and use it in GitHub Desktop.
Save dandelionadia/82e2ac961abfecc8b62ef1084e90e5ec to your computer and use it in GitHub Desktop.
import React, { useEffect, useRef } from "react";
interface CockpitProps {
onClick: any;
persons: any[];
personsLength: any;
}
export const Cockpit: React.FC<CockpitProps> = React.memo(props => {
const toggleBtnRef = useRef<HTMLButtonElement>(null);
useEffect(() => {
console.log("[Cockpit.js] useEffect");
const { current } = toggleBtnRef;
if (!current) {
return;
}
current.click();
}, []);
return (
<>
<h1>React App</h1>
<p>lorem foo</p>
<button ref={toggleBtnRef} onClick={props.onClick}>
Switch Name
</button>
</>
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment