首页 > 解决方案 > 从本地文件读取 JSON 但地图功能出错

问题描述

我关注了几篇关于如何在 React 中从本地文件读取 json 数据的文章,他们推荐使用 map 函数。喜欢https://morioh.com/p/316b1492cfda

我收到一个错误

Property 'map' does not exist on type '{ updated: number; }'.ts(223)

这是我的代码

import UpdatedFile from '../public/updated.json';

const[Updated,setUpdated]= useState("9/9/2020");

  const newdata = UpdatedFile.map((data) =>{  // This is where the error is coming
    return (
      setUpdated({map.updated})
    )
      });

这就是我的 JSON 文件的样子。

{
  "updated": 1599692605913
}

知道为什么它不将地图识别为有效功能吗?

标签: javascripttypescriptreact-nativenext.js

解决方案


推荐阅读