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

Using with React #20

Closed
nakullondhe opened this issue Oct 17, 2020 · 2 comments
Closed

Using with React #20

nakullondhe opened this issue Oct 17, 2020 · 2 comments

Comments

@nakullondhe
Copy link

nakullondhe commented Oct 17, 2020

It would be really helpful if we have details about using on react or other libraries

@Drarig29
Copy link
Owner

Drarig29 commented Oct 17, 2020

I just created an example for you: https://replit.com/@Drarig29/React-and-brackets-viewerjs

Basically, there is no React component created in this library because all the rendering is done manually with a defined CSS file and a JS file which adds bracketsViewer.render() in the window object.

So, just add this in your index.html file as stated in the README:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Drarig29/brackets-viewer.js/dist/brackets-viewer.min.css" />
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/Drarig29/brackets-viewer.js/dist/brackets-viewer.min.js"></script>

Or you could install the package using npm or yarn and serve these files from your node_modules folder (please don't serve the whole folder 😅).

Once you've done that, you can make your React component to wrap the viewer. For example:

import React, { useEffect } from 'react';

const URL = 'https://raw.githubusercontent.com/Drarig29/brackets-viewer.js/master/demo/db.json';

async function render() {
  const data = await fetch(URL).then(res => res.json());

  window.bracketsViewer.render({
    stages: data.stage,
    matches: data.match,
    matchGames: data.match_game,
    participants: data.participant,
  });
}

function App() {
  useEffect(() => {
    render();
  }, []);
  
  return <div className="brackets-viewer"></div>
}

export default App;

Obviously, you would host your own database and fetch this one (not my static demo db.json file). And this database would be manipulated by brackets-manager.js.

@Drarig29
Copy link
Owner

@nakullondhe closing this as you don't answer.

@Drarig29 Drarig29 changed the title No Description on how to use in projects like react. Using with React Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants