MCPcopy Index your code
hub / github.com/formkit/formkit / FormKitImpl

Function FormKitImpl

packages/react/src/FormKit.ts:177–268  ·  view source on GitHub ↗
(
  props: FormKitComponentProps<Props>,
  ref: Ref<FormKitNode | undefined>
)

Source from the content-addressed store, hash-verified

175}
176
177function FormKitImpl<Props extends FormKitInputs<Props>>(
178 props: FormKitComponentProps<Props>,
179 ref: Ref<FormKitNode | undefined>
180): ReactElement | null {
181 const slots = useStableSlots(props.children, props.slots)
182
183 const node = useInput({ ...props, slots } as any)
184
185 if (!node.props.definition) error(600, node)
186
187 useImperativeHandle(ref, () => node, [node])
188
189 useEffect(() => {
190 if (typeof props.onNode === 'function') {
191 props.onNode(node)
192 }
193 }, [node, props.onNode])
194
195 useReactiveStore(node.props.definition.component ? node.context : undefined)
196
197 if (node.props.definition.component) {
198 return createElement(node.props.definition.component as any, {
199 context: node.context,
200 slots,
201 })
202 }
203
204 const [schema, setSchema] = useState<FormKitSchemaDefinition>(
205 () => resolveSchemaState(node, props.sectionsSchema).schema
206 )
207 const [memoKey, setMemoKey] = useState<string | undefined>(
208 () => resolveSchemaState(node, props.sectionsSchema).memoKey
209 )
210
211 const generateSchema = useCallback(() => {
212 const nextState = resolveSchemaState(node, props.sectionsSchema)
213 setSchema(nextState.schema)
214 setMemoKey((existing) =>
215 existing === nextState.memoKey ? existing : nextState.memoKey
216 )
217 }, [node, props.sectionsSchema])
218
219 useEffect(() => {
220 generateSchema()
221 }, [generateSchema])
222
223 useEffect(() => {
224 const receipt = node.on('schema', () => {
225 setMemoKey((existing) => `${existing || ''}♻️`)
226 generateSchema()
227 })
228 return () => {
229 node.off(receipt)
230 }
231 }, [generateSchema, node])
232
233 useEffect(() => {
234 node.emit('mounted')

Callers

nothing calls this directly

Calls 7

useInputFunction · 0.90
errorFunction · 0.90
useReactiveStoreFunction · 0.90
createElementFunction · 0.90
useStableSlotsFunction · 0.85
resolveSchemaStateFunction · 0.85
generateSchemaFunction · 0.85

Tested by

no test coverage detected