DOM references
import Recks from 'recks';
import { Subject } from 'rxjs';
function App() {
const ref$ = new Subject();
ref$.subscribe(ref => {
ref.style.background = 'magenta';
});
return <div ref={ref$}>Hello!</div>;
}Focus example
import Recks from 'recks';
import { Subject } from 'rxjs';
import { withLatestFrom, takeUntil } from 'rxjs/operators';
function TextInputWithFocusButton(props$, { destroy$ }) {
const ref$ = new Subject();
const clicks$ = new Subject();
clicks$
.pipe(
withLatestFrom(ref$, (_, ref) => ref),
takeUntil(destroy$)
)
.subscribe(ref => {
ref.focus();
});
return (
<div>
<input ref={ref$} type="text" />
<button onClick={ ()=>clicks$.next(null) }>
Focus the input
</button>
</div>
);
}Last updated
Was this helpful?