简体   繁体   中英

React TypeScript Props Interface for string

I'm trying to pass the title down to the child Modal component

<Modal title='Register'/>

const Modal has the error

Type '(props: PropsWithChildren) => { props: PropsWithChildren; (Missing): any; }' is not assignable to type 'FunctionComponent'. Type '{ props: PropsWithChildren; (Missing): any; }' is missing the following properties from type 'ReactElement ReactElement Component)> | null) | (new (props: any) => Component)>': type, keyts(2322)

import React from 'react';

interface propsInterface {
    title: string; 
}

const Modal: React.FC<propsInterface> = (props) => {
  return (
    {props.title}
  );
}

export {Modal};

You've just forgotten to return jsx

const Modal: React.FC<propsInterface> = (props) => {
  return (
    props.title
  );
}

OR

const Modal: React.FC<propsInterface> = (props) => {
  return (
    <span>{props.title}</span>
  );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM