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

Injecting JSX #243

Open
electic opened this issue Jun 6, 2018 · 2 comments
Open

Injecting JSX #243

electic opened this issue Jun 6, 2018 · 2 comments

Comments

@electic
Copy link

electic commented Jun 6, 2018

How would I inject JSX into a parameter. As an example:

Here is my JSX code:

<ReactPaginate 
            breakClassName='{"page-item"}'
            pageClassName='{"page-item"}'
            breakLabel="(<a></a>)"
            breakClassName='{"page-link"}'
            previousClassName='{"page-item"}'
            nextClassName='{"page-item"}'
            pageLinkClassName='{"page-link"}'
            previousLinkClassName='{"page-link"}'
            nextLinkClassName='{"page-link"}'
            containerClassName='{"pagination"}'
            pageCount="{22}" 
            pageRangeDisplayed="{5}" 
            marginPagesDisplayed="{5}" 
        />

The breakLabel requires a node as a parameter. Here is how it would be if I wrote it in JSX:

         <ReactPaginate
            breakClassName="page-item"
            breakLabel={<a className="page-link">...</a>}
            pageClassName="page-item"
            previousClassName="page-item"
            nextClassName="page-item"
            pageLinkClassName="page-link"
            previousLinkClassName="page-link"
            nextLinkClassName="page-link"
          />

Any help appreciated.

@p3pp8
Copy link

p3pp8 commented Sep 12, 2018

@electic The only way i discovered is to use React.createElement(el,props,child). So for instance:

 <ReactPaginate
            breakClassName="page-item"
            breakLabel={React.createElement('a', {className:'page-link'}, '...')}
            pageClassName="page-item"
            previousClassName="page-item"
            nextClassName="page-item"
            pageLinkClassName="page-link"
            previousLinkClassName="page-link"
            nextLinkClassName="page-link"
          />

Where child can be a inner text(as the example) or in turn another React created element...

Hope it'll be useful...
Cheers

@electic
Copy link
Author

electic commented Sep 14, 2018

Yah this is what I was afraid of. Thanks for letting me know though!

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

2 participants