MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/reactjs/comments/civqd2/scriptui_write_react_without_jsx/ev9jg1c/?context=3
r/reactjs • u/[deleted] • Jul 28 '19
26 comments sorted by
View all comments
4
I'm really not following how this would work for a complex example.
Can you translate this ContactUs form into ScriptUI so I can see how props are supposed to be passed down?
function ContactUs(props) { const handleChange = (e) => { /* setState({ [e.target.name]: [e.target.value] }) */}; return ( <form> <div> <label> Enter your name <input type="text" name="contactedBy" onChange={handleChange} /> </label> </div> <div> <label> Enter your message <input type="text" name="message" onChange={handleChange} /> </label> </div> </form> ) }
6 u/[deleted] Jul 28 '19 This is as far as I got before getting utterly lost in HOCs:function ContactUs(props) { const handleChange = (e) => {} return View('form') ([View('div') (View('label') ( ['Enter your name', View('input', { type:'text', name:'contactedBy', onChange:handleChange })] ) ), View('div') (View('label') ( ['Enter your name'], View('input', {type:'text', name:'message', onChange:handleChange }) ) ) ]) } 4 u/[deleted] Jul 28 '19 Yes, this is right. Since its all JS functions, it enables more compositional style. So using HOCs is encouraged. Using deeply nested structures with the `View` primitive is only slightly more usable than `React.createElement` or `h`.
6
This is as far as I got before getting utterly lost in HOCs:
function ContactUs(props) { const handleChange = (e) => {} return View('form') ([View('div') (View('label') ( ['Enter your name', View('input', { type:'text', name:'contactedBy', onChange:handleChange })] ) ), View('div') (View('label') ( ['Enter your name'], View('input', {type:'text', name:'message', onChange:handleChange }) ) ) ]) }
4 u/[deleted] Jul 28 '19 Yes, this is right. Since its all JS functions, it enables more compositional style. So using HOCs is encouraged. Using deeply nested structures with the `View` primitive is only slightly more usable than `React.createElement` or `h`.
Yes, this is right. Since its all JS functions, it enables more compositional style. So using HOCs is encouraged. Using deeply nested structures with the `View` primitive is only slightly more usable than `React.createElement` or `h`.
4
u/[deleted] Jul 28 '19
I'm really not following how this would work for a complex example.
Can you translate this ContactUs form into ScriptUI so I can see how props are supposed to be passed down?