我正在使用 antd 通知组件,如下所示
import { notification } from "antd";
const Notification = ({ msg, type, clearMsg }) => {
return (
<div>
{notification[type]({
description: msg,
})}
{clearMsg()}
</div>
);
};
export default Notification;
Run Code Online (Sandbox Code Playgroud)
我只是在需要弹出通知的任何地方使用它。例如API响应失败后:
const onSubmit = async (e) => {
try {
const res = await login(data);
if (res.message) {
setError({ state: true, msg: res.message });
}
} catch (err) {
console.log(err);
}
};
Run Code Online (Sandbox Code Playgroud)
然后根据错误状态,我在返回正文中显示通知,如下所示:
{ error.state ?
<Notification
type="error"
msg="some msg"
clearMsg={() => setError({state: false, msg: ""})} : …Run Code Online (Sandbox Code Playgroud) 我正在使用 antd 菜单和菜单项组件。我的应用程序是这样的,如果您单击特定的菜单项,则 url 会发生变化并且该菜单项会被选中。但是,如果您在仪表板上,您还可以单击一个按钮,将 URL 更改为与单击该特定菜单项时相同的 URL,但在这种情况下,该菜单项不会被选中。如何解决这个问题:
<Menu
onClick={this.handleClick}
mode="vertical"
>
<Link to="/dashboard">
<Menu.Item key="mail" icon={<MailOutlined />}>
Dashboard
</Menu.Item>
</Link>
<Link to="/add-recipe">
<Menu.Item key="app" disabled icon={<AppstoreOutlined />}>
Add Recipes
</Menu.Item>
</Link>
</Menu>
Run Code Online (Sandbox Code Playgroud)
现在,在仪表板组件中还有一个按钮,允许用户直接从那里添加菜谱并在单击时更改 url,但不会选择“添加菜谱”菜单项,因为它不是手动单击的。如何根据 url 使其激活?