We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 87ff0c5 commit 6acb4d3Copy full SHA for 6acb4d3
app/javascript/bundles/HelloWorld/components/HelloWorld.jsx app/javascript/bundles/HelloWorld/components/HelloWorld.tsx
@@ -1,7 +1,13 @@
1
-import PropTypes from 'prop-types';
2
-import React, { useState } from 'react';
+import * as React from 'react';
+import { useState, FunctionComponent } from 'react';
3
4
-const HelloWorld = (props) => {
+export interface Props {
5
+ name: string;
6
+}
7
+
8
+// Note, you need to declare the type so that ReactOnRails.register has the
9
+// proper type.
10
+const HelloWorld: FunctionComponent<Props> = (props: Props) => {
11
const [name, setName] = useState(props.name);
12
13
return (
@@ -18,8 +24,4 @@ const HelloWorld = (props) => {
18
24
);
19
25
};
20
26
21
-HelloWorld.propTypes = {
22
- name: PropTypes.string.isRequired, // this is passed from the Rails view
23
-};
-
27
export default HelloWorld;
app/javascript/packs/hello-world-bundle.js app/javascript/packs/hello-world-bundle.ts
0 commit comments