[英]How to combine Material-table with Material-UI Dialog? (ReactJS)
[英]How to combine ReactJs Router Link and material-ui components (like a button)?
我需要找到一個解決方案,以便能夠將 react router 的功能與 material ui 組件結合在一起。
例如,我有這個場景:一個路由器和一個按鈕。 我試圖做的是將它們混合在一起,並重新設計它們。
所以從一個簡單的鏈接
<Link className={this.getClass(this.props.type)} to={`${url}`} title={name}>{name}</Link>
我嘗試創建一個材質 ui 按鈕如下
<Link className={this.getClass(this.props.type)} to={`${url}`} title={name}>
<FlatButton label={name} />
</Link>
但我有以下錯誤和 Javascript 中斷
invariant.js?4599:38Uncaught Invariant Violation: addComponentAsRefTo(...): 只有 ReactOwner 可以有 refs。 您可能正在向未在組件的
render
方法中創建的組件添加 ref,或者您加載了多個 React 副本(詳細信息: https : //gist.github.com/jimfb/4faa6cbfb1ef476bd105 )。
您知道如何處理這種情況嗎? 預先感謝您,如果您需要更多信息,請告訴我
這對我有用:
<FlatButton label="Details"
containerElement={<Link to="/coder-details" />}
linkButton={true} />
<Button
size="large"
color="primary"
onClick={() => {}}
variant="outlined"
component={RouterLink}
to={{
pathname: `enter your path name`,
}}
>
Click Here
</Button>
使用打字稿時可以嘗試這種方式:
import { NavLink as RouterLink } from "react-router-dom";
import {
Button,
Collapse,
ListItem,
makeStyles,
ListItemIcon,
ListItemText,
} from "@material-ui/core";
type NavItemProps = {
className?: string;
depth: number;
href?: string;
icon?: any;
info?: any;
open?: boolean;
title: string;
};
const NavItem: React.SFC<NavItemProps> = ({
const CustomLink = React.forwardRef((props: any, ref: any) => (
<NavLink
{...props}
style={style}
to={href}
exact
ref={ref}
activeClassName={classes.active}
/>
));
return (
<ListItem
className={clsx(classes.buttonLeaf, `depth-${depth}`)}
disableGutters
style={style}
key={title}
button
component={CustomLink}
{...rest}
>
<ListItemIcon>
{Icon && <Icon className={classes.icon} size="20" />}
</ListItemIcon>
<ListItemText primary={title} className={classes.title} />
</ListItem>
);
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.