我有labels的表单元素,我希望有唯一的ID来链接labels到具有htmlFor属性的元素.像这样的东西:
React.createClass({
render() {
const id = ???;
return (
<label htmlFor={id}>My label</label>
<input id={id} type="text"/>
);
}
});
Run Code Online (Sandbox Code Playgroud)
我过去常常根据this._rootNodeIDReact 0.13 生成ID,但它不可用.现在最好和/或最简单的方法是什么?
我一直在尝试为我的React项目设置一个测试环境,并且在导入CSS文件时遇到了Unexpected标记的问题.我将moduleNameMapper添加到package.json来修复它,现在我正面临这个问题.有谁知道我该怎么做才能解决这个问题?
> myProject@0.0.1 test C:\Users\admin\Documents\myApp
> jest
FAIL _tests_\Home.test.js
? Test suite failed to run
Configuration error:
Could not locate module react-datepicker/dist/react-datepicker-cssmodules.css (mapped as identity-obj-proxy)
Please check:
"moduleNameMapper": {
"/^.+\.(css|less)$/": "identity-obj-proxy"
},
"resolver": undefined
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.894s
Ran all test suites.
npm ERR! Test failed. See above for more details.
Run Code Online (Sandbox Code Playgroud)
package.json的开头部分
"jest": {
"transform": {
"^.+\\.jsx?$": "babel-jest"
},
"moduleNameMapper": {
"\\.(s?css|less)$": "identity-obj-proxy"
}
},
Run Code Online (Sandbox Code Playgroud)