Answers for "react functional component typescript"

3

react functional component typescript

import React from 'react';

interface Props {
  
}

export const App: React.FC<Props> = (props) => {
  return (
    <>
     <SomeComponent/>
    </>
  );
};
Posted by: Guest on May-29-2020
4

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> 
    )
  }
  
};
Posted by: Guest on July-12-2020
14

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')
);
Posted by: Guest on April-13-2020
0

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;
Posted by: Guest on May-28-2021

Code answers related to "react functional component typescript"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language