react-view icon indicating copy to clipboard operation
react-view copied to clipboard

Allow variables inside the function body

Open anishagg17 opened this issue 5 years ago • 5 comments

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

anishagg17 avatar Jun 10 '20 21:06 anishagg17

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

tajo avatar Jun 23 '20 02:06 tajo

()=>{

const on;  // talkingAboutThisVariable

return <Toggle title={on?"on":"off"}/>
}



anishagg17 avatar Jun 23 '20 08:06 anishagg17

Code like this works

export default () => {
  const label = 'ok';
  return (
    <button>{label}</button>
  );
}

tajo avatar Jun 23 '20 17:06 tajo

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

anishagg17 avatar Jun 23 '20 17:06 anishagg17

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...".

tajo avatar Jun 23 '20 19:06 tajo