MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/reactjs/comments/civqd2/scriptui_write_react_without_jsx/ev9hip7/?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> ) }
3 u/[deleted] Jul 28 '19 Sure, I'd do something like this:const Form = View("form"); const Field = (label, props) => { return View("div)( View("label")( label, View("input, { type: "text", ...props })() ) }; function ContactUs(props) { const handleChange = (e) => { }; return Form( Field("Enter your name") .set({ name: "contactedBy", onChange: handleChange }), Field("Enter your message") .set({ name: "message", onChange: handleChange }) ); } 1 u/[deleted] Jul 28 '19 Ok, looks like I was close, but this is obviously a lot cleaner than my first attempt. Thanks! 1 u/[deleted] Jul 28 '19 You’re welcome! Thank you for checking it out and caring enough to ask! I’ll work on adding more examples so this is clearer for the next dev
3
Sure, I'd do something like this:
const Form = View("form"); const Field = (label, props) => { return View("div)( View("label")( label, View("input, { type: "text", ...props })() ) }; function ContactUs(props) { const handleChange = (e) => { }; return Form( Field("Enter your name") .set({ name: "contactedBy", onChange: handleChange }), Field("Enter your message") .set({ name: "message", onChange: handleChange }) ); }
1 u/[deleted] Jul 28 '19 Ok, looks like I was close, but this is obviously a lot cleaner than my first attempt. Thanks! 1 u/[deleted] Jul 28 '19 You’re welcome! Thank you for checking it out and caring enough to ask! I’ll work on adding more examples so this is clearer for the next dev
1
Ok, looks like I was close, but this is obviously a lot cleaner than my first attempt. Thanks!
1 u/[deleted] Jul 28 '19 You’re welcome! Thank you for checking it out and caring enough to ask! I’ll work on adding more examples so this is clearer for the next dev
You’re welcome! Thank you for checking it out and caring enough to ask! I’ll work on adding more examples so this is clearer for the next dev
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?