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

can't pass an onclick to a custom component #76

Open
chadlavi opened this issue Jul 4, 2019 · 0 comments
Open

can't pass an onclick to a custom component #76

chadlavi opened this issue Jul 4, 2019 · 0 comments

Comments

@chadlavi
Copy link

chadlavi commented Jul 4, 2019

If I try to pass an onClick to a custom component, the component is not rendered and no error is shown in the console.

Here's how I'm defining my custom component:

import React, {createElement} from 'react'
import marksy from 'marksy/jsx'
import {
  Button,
  Link
} from '..'

interface MarkdownProps {
  markdown: any
}

export const Markdown = (props: MarkdownProps) => {

  const {markdown} = props

  const compile = marksy({
    createElement,
    elements: {
      a (props: any) {
        return (<Link {...props} />)
      },
    },
    components: {
      Button (props: any) {
        return (
          <Button {...props} />
        )
      }
    },
  })

  return compile(markdown).tree
}

if I pass this markdown:

<Button
  className='primary'
>foo</Button>

it renders the custom Button component as expected.

But if I pass this:

<Button
  className='primary'
  onClick={() => alert('ok')}
>foo</Button>

The Button is not rendered at all, and no errors show in the console.

I suspect this is a braces issue; if I pass the onClick prop but supply it a string instead, the component renders and I get a warning in the console that onClick expects a function.

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