recks
Search…
Subcomponents

Basic example

Component can contain other components:
1
import Recks from 'recks';
2
3
function Parent () {
4
return <div>
5
Hello, <Child /> !
6
</div>
7
}
8
9
function Child () {
10
return <span>child</span>
11
}
Copied!

Props

Probably you'll need to pass some properties from the parent to the child.
Each component accepts properties stream as the first argument. It's an Observable of properties from the parent. Once Parent re-renders a Child, the props$ stream will emit another object with updated properties:
1
import Recks from 'recks';
2
import { timer } from 'rxjs';
3
import { map } from 'rxjs/operators';
4
5
function Parent () {
6
return <div>{
7
timer(0, 1000).pipe(
8
map(i => <Child index={i} />)
9
)
10
}</div>
11
}
12
13
function Child (props$) {
14
const animal$ = props$.pipe(
15
map(props => props.index % 2 ? '🐱' : '🐭')
16
)
17
18
return <h1 style="text-align: center;">{animal$}</h1>
19
}
Copied!
Last modified 1yr ago
Copy link