Skip to content

I want to listen to the duplicate event of the component. Is there a way to achieve that? #60

Discussion options

You must be logged in to vote

Hi @tuthanhoancanh012
here is an example of how this can be implemented:

import {useBuilderContext, useComponentData} from '@react-form-builder/core'
import {useCallback} from 'react'

const MyInput = (props: any) => {
  const {builderMode} = useBuilderContext()
  const {store} = useComponentData()
  const handleChange = useCallback((event: any) => {
    if (builderMode === 'builder') {
      store.props.value ??= {}
      store.props.value.value = event.target.value
      return
    }
    props?.onChange?.(event.target.value)
  }, [builderMode, props, store])
  return (
    <Input
      className={`z-10 ${props.className}`}
      value={props.value}
      onChange={handleChange}
    />
  );

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@tuthanhoancanh012
Comment options

@sergeythrees
Comment options

@tuthanhoancanh012
Comment options

@sergeythrees
Comment options

Answer selected by sergeythrees
@tuthanhoancanh012
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants