How to use Function Components in React TypeScript code example
Example 1: react functional component typescript
import React from 'react';
interface Props {
}
export const App: React.FC = (props) => {
return (
<>
>
);
};
Example 2: How to use Function Components in React TypeScript
// Function Component ( with props and default props ):
import React from "react";
type Props = {
linkFirst: string,
routeFirst: string,
head?: string,
linkSecond?: string,
routeSecond?: string
};
/* Default props appear when no value for the prop
is present when component is being called */
const DefaultProps = {
head: "Navbar Head not found"
};
const Navbar: React.FC = (props) => {
return (
);
};
/* Initializing DefaultProps constant to defaultProps
so that this constant works. */
Navbar.defaultProps = DefaultProps;
export default Navbar;