Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Last active February 14, 2019 23:35
Show Gist options
  • Save ryanflorence/be2c385d714a3352389e30bd68e710f0 to your computer and use it in GitHub Desktop.
Save ryanflorence/be2c385d714a3352389e30bd68e710f0 to your computer and use it in GitHub Desktop.
// how do I write this:
const Profile: React.FunctionComponent<ProfileProps> = ({ userId, navigate }) => {
console.log(navigate);
return <div>{userId}</div>;
}
// as this:
function Profile({ userId, navigate }) {
console.log(navigate);
return <div>{userId}</div>;
}
// I tried this:
function Profile({ userId, navigate }): React.FunctionComponent<ProfileProps> {
console.log(navigate);
return <div>{userId}</div>;
}
// and this:
function Profile<React.FunctionComponent<ProfileProps>>({ userId, navigate }){
console.log(navigate);
return <div>{userId}</div>;
}
// neither work.
// Also we can't just do function Profile(props: ProfileProps) {}
// because Profile can be passed to a HOC or a "component" prop
// and w/o the React.FunctionComponent stuff it fails the type checking
// on React.ComponentType
@sunify
Copy link

sunify commented Feb 13, 2019

@artisonian nice solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment