pmndrs/react-nil
소개
⃝ React용 null 렌더러
웹 및 앱 개발측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalNothing to see here ...
Quite so. This package allows you to bring React's high-level component abstraction to Node or wherever you need it. Why not manage your REST endpoints like routes on the client, users as components with mount/unmount lifecycles, self-contained separation of concern, and clean side effects? Suspense for requests, etc.
You can try a small demo here: https://codesandbox.io/s/react-nil-mvpry
How does it work?
The following renders a logical component without a view, it renders nothing, but it has a real lifecycle and is managed by React regardless.
import { useState, useEffect } from 'react'
import { render } from 'react-nil'
function Foo() {
const [active, set] = useState(false)
useEffect(() => void setInterval(() => set((a) => !a), 1000), [])
// false, true, ...
console.log(active)
}
render(<Foo />)
We can take this further by rendering made-up elements that get returned as a reactive JSON tree from render.
You can take a snapshot for testing via React.act which will wait for effects and suspense to finish.
import { useState, useEffect, act } from 'react'
import { render } from 'react-nil'
declare module 'react' {
namespace JSX {
interface IntrinsicElements {
timestamp: Record<string, unknown>
}
}
}
function Test() {
const [value, setValue] = useState(-1)
useEffect(() => setValue(Date.now()), [])
return <timestamp value={value} />
}
const container = await act(async () => render(<Test />))
// { type: 'timestamp', props: { value: number }, children: [] }
console.log(container.head)
관련 프로젝트 살펴보기
불러오는 중…