( props: FormKitComponentProps<Props>, ref: Ref<FormKitNode | undefined> )
| 175 | } |
| 176 | |
| 177 | function 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') |
nothing calls this directly
no test coverage detected