How would you convert this JSX into a Hyperstack Component?
const Stopwatch = () => (
<ReactStopwatch
seconds={0}
minutes={0}
hours={0}
limit="00:00:10"
onChange={({ hours, minutes, seconds }) => {
// do something
}}
onCallback={() => console.log('Finish')}
render={({ formatted, hours, minutes, seconds }) => {
return (
<div>
<p>
Formatted: { formatted }
</p>
<p>
Hours: { hours }
</p>
<p>
Minutes: { minutes }
</p>
<p>
Seconds: { seconds }
</p>
</div>
);
}}
/>
);
This syntax render={({ formatted, hours, minutes, seconds }) is new to me. Are these props?
I am trying to use this NPM module:
The
renderprop renders a functional component. A functional component is a function, such that the arguments are props, and the return value is the component to be rendered.Therefor, we need to convert your render prop to opal.
There's one gotcha here. The first is that
propsis being passed as a javascript object. We need that to be ruby, so we wrap it inNative.Step two is exposing the stopwatch class to Hyperstack.
Under app/javascript/packs, edit
hyperstack.jsto include react-stopwatch.Now you can use
Stopwatchin your code.Putting this together, you get: