Skip to content

Commit 6acb4d3

Browse files
committed
Covert HelloWorld to TSX
1 parent 87ff0c5 commit 6acb4d3

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

app/javascript/bundles/HelloWorld/components/HelloWorld.jsx app/javascript/bundles/HelloWorld/components/HelloWorld.tsx

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import PropTypes from 'prop-types';
2-
import React, { useState } from 'react';
1+
import * as React from 'react';
2+
import { useState, FunctionComponent } from 'react';
33

4-
const HelloWorld = (props) => {
4+
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) => {
511
const [name, setName] = useState(props.name);
612

713
return (
@@ -18,8 +24,4 @@ const HelloWorld = (props) => {
1824
);
1925
};
2026

21-
HelloWorld.propTypes = {
22-
name: PropTypes.string.isRequired, // this is passed from the Rails view
23-
};
24-
2527
export default HelloWorld;

0 commit comments

Comments
 (0)