我使用 next.js、typescript 和 React 项目设置了故事书。该项目渲染良好,但故事书中断并给我错误:“找不到模块:错误:无法解析......中的'组件/原子'”似乎组件的路径导致它中断:
import { Element } from 'components/atoms';
Run Code Online (Sandbox Code Playgroud)
但以下有效:
import { Element } from '../../atoms
Run Code Online (Sandbox Code Playgroud)
我有一个 tsconfig.json 文件,其中包含以下内容:
"compilerOptions": {
"baseUrl": "src",
},
"include": [
"src/**/*.ts",
"src/**/*.tsx"
],
...
Run Code Online (Sandbox Code Playgroud)
我尝试了网上的一些建议,但似乎都没有解决路径问题。我使用以下内容在 .storybook 文件夹中创建了 webpack.config.js,但仍然出现错误。
module.exports = {
...
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules']
}
};
Run Code Online (Sandbox Code Playgroud)
我不想../../在调用文件时使用,而只是能够使用该./components结构。
我在 React 项目中使用 Material UI,无法检测何时按下 Enter 键。我已经尝试了以下我认为应该有效的方法,但仍然无法检测到该事件,不确定我错过了什么。
我有一个自定义 MUI 组件
const [search, setSearch] = useState('');
const handleChange = (event) => {
setSearch(event.target.value);
if (event.keyCode == 13) {
console.log('enter key was pressed');
}
}
<SearchBox
value={search}
onChange={handleChange}
placeholder="enter your search here"
}}
/>
Run Code Online (Sandbox Code Playgroud)