Created
April 1, 2020 14:00
-
-
Save dandelionadia/82e2ac961abfecc8b62ef1084e90e5ec to your computer and use it in GitHub Desktop.
This file contains 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, { 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