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

🏏 A new way of React Components without Hooks

License

NotificationsYou must be signed in to change notification settings

nanxiaobei/react-split-components

Repository files navigation

kee.so

Create now ➫🔗 kee.so


React Split Components (RiC)

A new way of React Components without Hooks.

English |简体中文


Introduction

Introducing React Split Components →

React Function Components in closure style.

Write React like Svelte, just natural and fluent code.

Features

  • 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

Simple Example

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);

Full Example

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);

Online Demo

Edit react-split-components-final

License

MIT License (c)nanxiaobei

About

🏏 A new way of React Components without Hooks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp