我使用 Material-ui 中的 Snackbar 来显示警报。我想在 5 秒后自动隐藏该 Snackbar 但autoHideDuration它不起作用。
<Snackbar
autoHideDuration={3000}
open={true}
ContentProps={{
'aria-describedby': 'message-id',
}}
message={<span id="message-id"> Message </span>}
/>Run Code Online (Sandbox Code Playgroud)
我目前正在构建一个React组件库,并将其与Webpack 4捆绑在一起。
从构建库的捆绑包到将其发布到npm注册表中,一切工作都很好。
但是,然后,我无法将其任何组件导入另一个React应用程序中,并在运行时得到以下错误消息:
元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件),但得到:未定义。您可能忘记了从定义文件中导出组件,或者可能混淆了默认导入和命名导入。
这是相关的代码:
我的组件库中的一个哑组件:
button/index.js
import React from "react";
const Button = () => <button>Foobar</button>;
export { Button };
Run Code Online (Sandbox Code Playgroud)
我图书馆的主要入口index.js:
import { Button } from "./src/components/Button";
export { Button };
Run Code Online (Sandbox Code Playgroud)
我的Webpack配置webpack.config.js:
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
module.exports = {
entry: "./index.js",
plugins: [new CleanWebpackPlugin()],
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
},
output: {
filename: "index.js",
path: path.resolve(__dirname, "dist"), …Run Code Online (Sandbox Code Playgroud) 所以,我是 React 世界的初学者。context我不明白:在react-redux应用程序中使用有意义吗?connect或者使用函数会更好?
我已经使用npm将服务安装为“ npm install serve -g”,并且还使用了纱线“ yarn global add serve”,但是当我尝试运行“ serve -s build”时,它说“找不到命令'serve'”。
reactjs ×3
javascript ×1
linux ×1
material-ui ×1
npm ×1
redux ×1
serve ×1
snackbar ×1
webpack ×1