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

Custom content type for Headless Tippy Singleton #365

Open
angeloanan opened this issue Jul 9, 2022 Discussed in #355 · 0 comments
Open

Custom content type for Headless Tippy Singleton #365

angeloanan opened this issue Jul 9, 2022 Discussed in #355 · 0 comments

Comments

@angeloanan
Copy link

Discussed in #355

Moved to an issue since its been ~4 months without any update.

Originally posted by angeloanan March 12, 2022
Hi,

I would like to use a custom Typescript type for the render method of a Headless Tippy Singleton. Here is an example code:

import Tippy, { useSingleton } from '@tippyjs/react'

interface CustomRenderDataType {
  some: string
  data: string[]
}

const customDataToPass: CustomRenderDataType = { some: 'custom', data: ['type'] }

const Something = () => {
  const [source, target] = useSingleton({ overrides: ['render'] })

  return (
    <>
      <Tippy
        singleton={source}
        render={(attrs, content) => <SomeComponent attr={attrs} data={content} />}
      />
      {/*               ^ I want this to have a custom type! */}
      {/* In here, Typescript complains that ReactNode (`content`) is not assignable to type 'CustomRenderDataType'! */}

      <Tippy singleton={target} content={customDataToPass} />
      {/*                       ^ Typescript allows this but technically should be disallowed since CustomRenderDataType != React.ReactNode */}
    </>
  )
}

// Example render Component that takes in a custom type
const SomeComponent = ({ attr, data }: { attr: unknown; data: CustomRenderDataType }) => {
  // TODO
  return <></>
}

Is there a way to do it as of now?

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