简体   繁体   English

React.FC 迭代 json 道具

[英]React.FC iterate over json props

i am a React/Typescript newbie.我是 React/Typescript 新手。 I have a question.我有个问题。 I am converting an app from straight react to also using typescript.我正在将应用程序从直接反应转换为也使用 typescript。 So I converted a functional component to a React.FC.所以我将一个功能组件转换为 React.FC。 I was using a json map inside the original method but that doesnt seem to work with FC.我在原始方法中使用了 json map,但这似乎不适用于 FC。 Do you have any suggestions?你有什么建议吗? It chokes on the 'const rows = jeffsData.map(...' saying 'map' doesnt exist. I didnt find anything helpful on the inet and I have searched. Thank you! 'const rows = jeffsData.map(...' 说 'map' 不存在。我在 inet 上没有找到任何有用的东西,我已经搜索过了。谢谢!

type shopData = {
DisplayName: string;
SJ_ID: string;
IsGoodJeffOrBadGeoff: boolean;
LastUpdatedTimeStamp: string;

};

interface jeffsDataProps {
jeffsData : shopData;
}

const TableBody: React.FC<jeffsDataProps> = ({jeffsData}) => {
const rows = jeffsData.map((row, index) => {
return (
<tr key={index}>
<td style={{ textAlign: 'left' }}>{row.DisplayName}</td>
<td>{row.SJ_ID}</td>
<td>{row.IsGoodJeffOrBadGeoff}</td>
<td>{row.LastUpdatedTimeStamp}</td>

</tr>
);
});

I think you intended to make jeffsData an array(map is not available on objects) to do that change interface to我认为您打算使jeffsData成为一个数组(映射在对象上不可用)来更改接口

interface jeffsDataProps {
jeffsData : shopData[];
}

and pass an array as the jeffsData并传递一个数组作为 jeffsData

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 打字稿React.FC<Props> 困惑 - TypeScript React.FC<Props> confusion 打字稿 - React.FC 是任何而不是检查道具 - Typescript - React.FC is any and not checking props React.FC 中的泛型类型<Props<T> &gt; - GenericType in React.FC<Props<T>> React.FC<specificprops> 不可分配给 React.FC<genericprops> ,但道具是可分配的</genericprops></specificprops> - React.FC<SpecificProps> is not assignable to React.FC<GenericProps>, but props are assignable 将 Formik 与 React.FC 一起使用 - Use Formik with React.FC React.FC泛型之一 - React.FC generic one of Typescript 在 React 功能组件(React.FC<props> ) 错误的道具是作为道具发送的吗?</props> - Typescript isn't complaining when a React Functional Component (React.FC<Props>) with wrong props is send as a prop? typescript React.FC如何表达给定道具(来自用户)与组件内的最终道具之间的差异 - typescript React.FC how to express difference between given props(from user) to final props inside the component 如何使用 React.FC<props> 当子节点可以是 React 节点或函数时键入 - How to use React.FC<props> type when the children can either be a React node or a function 如果我为 React.FC 提供泛型类型,为什么需要指定 props 类型? - Why do I need to specify the props type if I supply a generic type to a React.FC?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM