-
-
Notifications
You must be signed in to change notification settings - Fork 634
/
Copy pathHelloWorldHooksContext.jsx
34 lines (30 loc) · 1.01 KB
/
HelloWorldHooksContext.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Example of using hooks when taking the props and railsContext
// Note, you need the call the hooks API within the react component stateless function
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import css from '../components/HelloWorld.module.scss';
import RailsContext from '../components/RailsContext';
// You could pass props here or use the closure
const HelloWorldHooksContext = (props, railsContext) => {
const Result = () => {
const [name, setName] = useState(props.helloWorldData.name);
return (
<>
<h3 className={css.brightColor}>Hello, {name}!</h3>
<p>
Say hello to:
<input type="text" value={name} onChange={(e) => setName(e.target.value)} />
</p>
<p>Rails Context :</p>
<RailsContext {...{ railsContext }} />
</>
);
};
Result.propTypes = {
helloWorldData: PropTypes.shape({
name: PropTypes.string,
}).isRequired,
};
return Result;
};
export default HelloWorldHooksContext;