uber / react-view

React View is an interactive playground, documentation and code generator for your components.
https://react-view.pages.dev
MIT License
697 stars 41 forks source link

Allow variables inside the function body #39

Open anishagg17 opened 4 years ago

anishagg17 commented 4 years ago

currently variables inside the function body are only made available when they are passed to the component itself and are mentioned stateful:true , no support for other type of variables is found

tajo commented 4 years ago

Not sure what you mean. Can you provide some examples? stateful: true is to create a state while using the hook.

anishagg17 commented 4 years ago
()=>{

const on;  // talkingAboutThisVariable

return <Toggle title={on?"on":"off"}/>
}
tajo commented 4 years ago

Code like this works

export default () => {
  const label = 'ok';
  return (
    <button>{label}</button>
  );
}
anishagg17 commented 4 years ago

yes but how to get that const label = 'ok'; within the code body ?

tajo commented 4 years ago

Hm, not sure what exactly your use-case is. If you are using "live-code only" setup, you can pass it through initialCode: https://react-view.netlify.app/?path=/story/useview--live-code-only

If you are using knobs where the code auto-generated, there is no way to tell react-view "add this variable right here...".