react functional component typescript
import React from 'react';
interface Props {
}
export const App: React.FC<Props> = (props) => {
return (
<>
<SomeComponent/>
</>
);
};
react functional component typescript
import React from 'react';
interface Props {
}
export const App: React.FC<Props> = (props) => {
return (
<>
<SomeComponent/>
</>
);
};
TYPESCript props class component
class Test extends Component<PropsType,StateType> {
constructor(props : PropsType){
super(props)
}
render(){
console.log(this.props)
return (
<p>this.props.whatever</p>
)
}
};
functional component react
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
function App() {
return (
<div>
<Welcome name="Sara" /> <Welcome name="Cahal" /> <Welcome name="Edite" /> </div>
);
}
ReactDOM.render(
<App />,
document.getElementById('root')
);
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> = (props) => {
return (
<div>
<nav>
{ props.head }
<ul>
<li>
<a href={ props.routeFirst }> {props.linkFirst} </a>
<li>
<a href= { props.routeSecond }> {props.linkSecond} </a>
</li>
</ul>
</nav>
</div>
);
};
/* Initializing DefaultProps constant to defaultProps
so that this constant works. */
Navbar.defaultProps = DefaultProps;
export default Navbar;
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us