React TypeScript Props Interface for string



我正在尝试将title传递给子模态组件

<Modal title='Register'/>

const Modal有错误

类型 '(道具: 道具与孩子( => { 道具: 道具与儿童;(缺失(:任何;}' 不能分配给类型"函数组件"。 键入 '{ 道具:道具与孩子;(缺失(:任何;}' 缺少类型"反应元素反应元素组件"中的以下属性> |空( |(新 (道具: 任意( => 组件(>': 类型, 键(2322(

import React from 'react';
interface propsInterface {
title: string; 
}
const Modal: React.FC<propsInterface> = (props) => {
return (
{props.title}
);
}
export {Modal};

你只是忘了返回jsx

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

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

最新更新