recks
Search…
Lifecycle
Unlike React components, in Recks component function is executed only once in a given component lifetime:
1
function App() {
2
console.log('🦄'); // <- only once per component!
3
4
return <div>...</div>
5
}
Copied!
This means that it's safe to create Subjects here to store component state, for example
1
function App() {
2
// create local state Subject
3
const state$ = new Subject();
4
const onClick = () => state$.next(+1);
5
6
return <div>
7
...
8
<button onClick={ onClick }>btn</button>
9
...
10
</div>
11
}
Copied!

Updates

All incoming property updates are provided via props$ — an Observable, passed as a first argument to your component. See Subcomponents section for details.
And only you control the output updates by placing your Observables where needed!

Automatic subscription

When you use an Observable anywhere in your component:
1
function App() {
2
return <div>{ timer(0, 1000) }</div>
3
}
Copied!
Recks will automatically subscribe to that stream when the Component is mounted and will unsubscribe from it when the Component is unmounted. You don't have to worry about that!

destroy$

Additionally, you can utilize lifecycle stream, that emits on Component unmount. It emits once and then completes.
1
function App(props, { destroy$ }) {
2
// do custom sideeffects
3
timer(0, 1000).pipe(
4
takeUntil(destroy$)
5
)
6
.subscribe(t => {
7
console.log('ping @ ' + t);
8
});
9
10
return <div>Hello!</div>
11
}
Copied!
Last modified 1yr ago