React onClick 不在组件上触发
React onClick not firing on component
我正在将 Remix 与 React 和 TS 结合使用。
我有一个名为 Map.tsx 的简单 class 组件,用于 index.tsx.
Map.tsx
class Map extends React.Component {
constructor(props: any) {
super(props);
this.regionClicked = this.regionClicked.bind(this);
}
render() {
return (
<div>
<button onClick={() => alert("ciao")}>a</button>
</div>
)
}
}
index.tsx
import Map from "../components/index/map/Map";
class Index extends React.Component {
constructor(props: any) {
super(props);
}
render() {
return (
<div>
<Map />
</div>
)
}
}
已使用 root.tsx 文件中的 Scripts 标签修复。
可用示例 here
import { Scripts } from "remix";
function Document({ children }: { children: React.ReactNode; title?: string }) {
return (
<html lang="en">
<head>
<Meta />
<Links />
</head>
<body>
<Header />
{children}
<Footer />
<Scripts />
{process.env.NODE_ENV === "development" ? <LiveReload /> : null}
</body>
</html>
);
}
我正在将 Remix 与 React 和 TS 结合使用。 我有一个名为 Map.tsx 的简单 class 组件,用于 index.tsx.
Map.tsx
class Map extends React.Component {
constructor(props: any) {
super(props);
this.regionClicked = this.regionClicked.bind(this);
}
render() {
return (
<div>
<button onClick={() => alert("ciao")}>a</button>
</div>
)
}
}
index.tsx
import Map from "../components/index/map/Map";
class Index extends React.Component {
constructor(props: any) {
super(props);
}
render() {
return (
<div>
<Map />
</div>
)
}
}
已使用 root.tsx 文件中的 Scripts 标签修复。 可用示例 here
import { Scripts } from "remix";
function Document({ children }: { children: React.ReactNode; title?: string }) {
return (
<html lang="en">
<head>
<Meta />
<Links />
</head>
<body>
<Header />
{children}
<Footer />
<Scripts />
{process.env.NODE_ENV === "development" ? <LiveReload /> : null}
</body>
</html>
);
}