Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

callback in Props can not get current data #307

Open
sinbargit opened this issue Jun 6, 2024 · 0 comments
Open

callback in Props can not get current data #307

sinbargit opened this issue Jun 6, 2024 · 0 comments

Comments

@sinbargit
Copy link

sinbargit commented Jun 6, 2024

Below is my code

    const x = Math.random()
  console.log('--0--', x)
  const toolItems = useMemo(
    () =>
      [
        { key: 'Header' },
        { key: 'Paragraph' },
        { key: 'Dropdown' },
        { key: 'Checkboxes' },
        { key: 'RadioButtons' },
        { key: 'TextInput' },
        { key: 'EmailInput' },
        { key: 'PhoneNumber' },
        { key: 'NumberInput' },
        { key: 'Image' },
        {
          key: 'MyCarousel',
          element: 'CustomElement',
          component: MyCarousel,
          type: 'custom',
          bare: true,
          forwardRef: true,
          field_name: 'my_carousel_',
          name: 'My Carousel',
          icon: 'fa fa-cog',
          props: {
            matiralMap,
            form: () => {
              console.log('--1--', x)
              console.log('-----return  ', extraData, new Date())
              return extraData
            },
          },
          label: 'Carousel',
        },
      ] as any,
    [extraData]
  )

When I call form() in MyCarousel components. The console prints the old "x" value. This value is the value when MyCarousel was just initialized, but this value has been updated, but the latest one has not been printed. Why? Aren't they in the same scope?
please see below screenshot, it looks so strange.
Is there anyway I can get the lastest value of x?
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant