Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

(WIP) transform mutable variables to react-state

License

NotificationsYou must be signed in to change notification settings

barelyhuman/babel-plugin-mutable-react-state

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

(WIP) Use mutable variable declarations as state in react

Test

UNSTABLEThe plugin is still under development so isn't recommended for production

Caveats (for now)

  • Doesn't support pragma right now
  • Update Expressions aren't supported (eg: variableName++) on numbers won't work.

Install

The plugin assumes you already havejsx enabled on babel or are usingpreset-react in your setup.

npm i babel-plugin-mutable-react-state# oryarn add babel-plugin-mutable-react-state
// .babelrc[  {"plugins": ["babel-plugin-mutable-react-state"]  }]

Usage

You write state with a prefix$ and that's converted touseState accordingly.

import*asReactfrom'react'functionComponent(){let$a=1constonPress=()=>{$a+=1}return(<div><p>{$a}</p><buttononClick={onPress}>Press</button></div>)}import*asReactfrom'react'functionComponent(){const[a,setA]=React.useState(1)constonPress=()=>{setA(a+1)}return(<div><p>{a}</p><buttononClick={onPress}>Press</button></div>)}

License

MIT


[8]ページ先頭

©2009-2025 Movatter.jp