[英]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.