1. 按官方文档,react-json-pretty 和 react-json-view 都有不能import不能使用的问题
1.1 Error 1
1. mismatched import name: should be reactJsonPretty, but found JSONPretty.
2. mismatched import name: should be reactJsonView, but found ReactJson.
1.2 Error 2
改成reactJsonPretty或者reactJsonView后,不能create Element,或者browser say can’t recognize reactJsonPretty / reactJsonView,因为需要大写字母开头
2. 解决方案
2.1 react-json-pretty
1 2 3 | const JSONPretty = require("react-json-pretty"); ... <JSONPretty data={Your Json Object} onJSONPrettyError={e => console.error(e)} /> |
2.1 react-json-view
在tslint.json里给它起个别名:
1 2 3 4 5 6 | "rules": { ... "import-name": [true, { "reactJsonView": ReactJson }] } |
之后就可以正常import和使用了:
1 2 3 | import ReactJson from 'react-json-view'; ... <ReactJson src={Your Json Object} /> |
没有尝试给react-json-pretty起别名,说不定也行