Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用TypeScript向ReactJS函数组件传递1个、2个或无参数?_Javascript_Reactjs_Typescript - Fatal编程技术网

Javascript 如何使用TypeScript向ReactJS函数组件传递1个、2个或无参数?

Javascript 如何使用TypeScript向ReactJS函数组件传递1个、2个或无参数?,javascript,reactjs,typescript,Javascript,Reactjs,Typescript,这是我的代码: interface GetMarketingContentProps { modules?: object[] filter?: string } const getMarketingContent: React.FunctionComponent<GetMarketingContentProps> = ({ modules = null, filter = '' }: GetMarketingContentProps) => { 接口GetMa

这是我的代码:

interface GetMarketingContentProps {
  modules?: object[]
  filter?: string
}

const getMarketingContent: React.FunctionComponent<GetMarketingContentProps> = ({
  modules = null, filter = ''
}: GetMarketingContentProps) => {
接口GetMarketingContentProps{
模块?:对象[]
过滤器?:字符串
}
const getMarketingContent:React.FunctionComponent=({
模块=空,筛选器=“”
}:GetMarketingContentProps)=>{
我正在尝试传递1个或2个参数,或者不传递任何参数。我如何才能做到这一点?我当然是在reactJS中使用TypeScript


非常感谢。

这些都是道具,而且总是一个对象。该对象可能是空的。到目前为止,您尝试了什么?功能组件的道具总是一个参数:一个对象。对象的属性可以是可选的,您已经在接口中指定了。您当前的实现有哪些问题?c当我没有传递它所抱怨的参数,并告诉我应该传递1个或多个参数时,当前实现。唯一的方法是使用扩展运算符吗?并测试参数[0]或[1]是否存在?