Skip to content

Commit

Permalink
fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
theforestvn88 committed May 22, 2024
1 parent c41e5f6 commit a762887
Showing 1 changed file with 20 additions and 34 deletions.
54 changes: 20 additions & 34 deletions spec/dummy/client/app/startup/HelloTurboStream.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,27 @@ import RailsContext from '../components/RailsContext';

import css from '../components/HelloWorld.module.scss';

class HelloTurboStream extends React.Component {
static propTypes = {
helloTurboStreamData: PropTypes.shape({
name: PropTypes.string,
}).isRequired,
railsContext: PropTypes.object,
};

constructor(props) {
super(props);
this.state = props.helloTurboStreamData;
this.setNameDomRef = this.setNameDomRef.bind(this);
this.handleChange = this.handleChange.bind(this);
}

setNameDomRef(nameDomNode) {
this.nameDomRef = nameDomNode;
}
const HelloTurboStream = ({ helloTurboStreamData, railsContext }) => {
const [name, setName] = useState(helloTurboStreamData.name);
const nameDomRef = useRef(null);

handleChange() {
const name = this.nameDomRef.value;
this.setState({ name });
}

render() {
const { name } = this.state;
const { railsContext } = this.props;
const handleChange = () => {
setName(nameDomRef.current.value);
};

return (
<div>
<h3 className={css.brightColor}>Hello, {name}!</h3>
{railsContext && <RailsContext {...{ railsContext }} />}
</div>
);
}
}
return (
<div>
<h3 className={css.brightColor}>Hello, {name}!</h3>
{railsContext && <RailsContext {...{ railsContext }} />}
</div>
);
};

HelloTurboStream.propTypes = {
helloTurboStreamData: PropTypes.shape({
name: PropTypes.string,
}).isRequired,
railsContext: PropTypes.object,
};

export default HelloTurboStream;

0 comments on commit a762887

Please sign in to comment.