- Notifications
You must be signed in to change notification settings - Fork9
🏏 A new way of React Components without Hooks
License
NotificationsYou must be signed in to change notification settings
nanxiaobei/react-split-components
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Create now ➫🔗 kee.so
A new way of React Components without Hooks.
English |简体中文
Introducing React Split Components →
React Function Components in closure style.
Write React like Svelte, just natural and fluent code.
- Remove the dependence on Hooks, but not purely Functional Components
- Only at the writing level, no need for ESLint support
- Like High-Order Components, it's a "design pattern", not API, no lib needed
functiondemo({ atom}){conststate=atom({count:0,});constonClick=()=>{state.count+=1;};return()=>{const{ count}=state;return(<><h1>{count}</h1><buttononClick={onClick}>Click me</button></>);};}constDemo=create(demo);
functiondemo({ props, atom, onMount, onEffect}){conststate=atom({// for useStateloading:true,data:null,count:0,// for useMemopower:()=>state.count*state.count,text:()=>`${props.theme} ~${state.count}`,});// for useRefconstcountRef={current:null};// for useCallbackconstonClick=()=>{const{ setTheme}=props;setTheme();state.count+=1;};constgetData=()=>{request().then((res)=>{state.data=res.data;state.loading=false;});};// for useEffectonMount(()=>{getData();console.log('mount!');return()=>{console.log('unmount!');};});onEffect(state.power,(val,prevVal)=>{console.log('enter state.power',val,prevVal);return()=>{console.log('clear state.power',val,prevVal);};});constonReload=()=>{state.loading=true;getData();};return()=>{const{ theme}=props;const{ loading, data, count, power, text}=state;return(<><h1>{loading ?'loading...' :JSON.stringify(data)}</h1><buttononClick={onReload}>Reload data</button><h1>{theme}</h1><h1ref={countRef}>{count}</h1><h1>{power}</h1><h1>{text}</h1><buttononClick={onClick}>Click me</button></>);};}constDemo=create(demo);
About
🏏 A new way of React Components without Hooks
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.
