question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

It’d be great if users could make their designs stateful.

My thinking is that we could do this in a code-oriented way by allowing usage of React hooks like this:

const [ firstName, setFirstName ] = useState('');
const [ lastName, setLastName ] = useState('');

<TextField label="First name" value={name} onChange=(event => setFirstName(event.target.value)} />
<TextField label="Last name" value={name} onChange=(event => setLastName(event.target.value)} />

For this to work, we’d need to treat the last n number of JSX elements as an implicitly returned fragment, i.e. behind the scenes we’d turn it into a component that looks like this:

() => {
  const [ firstName, setFirstName ] = useState('');
  const [ lastName, setLastName ] = useState('');

  return (
    <React.Fragment>
      <TextField label="First name" value={name} onChange=(event => setFirstName(event.target.value)} />
      <TextField label="Last name" value={name} onChange=(event => setName(event.target.value)} />
    </React.Fragment>
  );
};

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

6reactions
ezhikovcommented, Mar 12, 2020

Hi. Since code now transpiled through babel, it’s possible to alter it, so it would be component itself. I coded some solution, that takes user code, wraps it into React.createElement(function () {}) and adds return to jsx code.

const [value, setValue] = React.useState('');

<input value={value} onChange={event => setValue(event.target.value)}/>

is transformed to


React.createElement(function() {
  const [value, setValue] = React.useState('');

  return <input value={value} onChange={event => setValue(event.target.value)}/>
})

I see interesting side-effect of this solution - you don’t need React.Fragment anymore.

Right now solution is fastcoded as PoC, so there is few broken tests. If you interested, I can continue working on it.

3reactions
armand1mcommented, Feb 27, 2020

I just got a very simple solution:

In my components file, I export this one line component:

export const FunctionWrapper = ({ children }) => children()

so it allows me to do the following on playroom:

<FunctionWrapper>
  {() => {
    const [state, setState] = React.useState(0);

    return (
      <>
        <p>{state}</p>
        <button onClick={() => setState(prevState => prevState + 1)}>
          Increase
        </button>
      </>
    );
  }}
</FunctionWrapper>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Customer Service | Support - State Water Heaters
Phone. 1-866-667-4960. Residential Water Heater Tech Support Hours. Monday - Friday 8:00 AM - 10:00 PM EST. Saturday - Sunday 9:00 AM -...
Read more >
Welcome to the OCSE State Plan Data - Child Support Portal
Office of Child Support Enforcement. Administration for Children & Families ... Welcome to the OCSE State Plan Data. You are accessing a U.S....
Read more >
What is State Support | IGI Global
What is State Support? Definition of State Support: A set of protective measures provided by a state to a certain industry or sector....
Read more >
State support Definition | Law Insider
State support means grant by the State of any administrative support, asset-based support, foregoing revenue benefits support, undertaking contingent ...
Read more >
Pennsylvania Child Support Program
Welcome to the Pennsylvania Child Support Program. On-the-go access to child support information and services. My Cases. Register or log in to manage...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found