GithubHelp home page GithubHelp logo

miroapp / miro-react-hooks Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 0.0 413 KB

Collection of React Hooks wrappers for Miro WebSDK

License: BSD 3-Clause "New" or "Revised" License

JavaScript 6.46% Shell 0.35% TypeScript 91.85% HTML 1.35%

miro-react-hooks's Introduction

miro-websdk-react-hooks NPM version

Collection of React hooks to interact with Miro Platform WebSDK.

Add a bit of ✨reactivity✨ to your Miro app.

Use it!

$ npm install @mirohq/websdk-react-hooks
// or
$ yarn add @mirohq/websdk-react-hooks

Inject Miro instance

Wrap your components with MiroProvider and inject the global instance of Miro WebSDK.

import { MiroProvider } from "@mirohq/websdk-react-hooks";

const App: React.FC = ({ children }) => <MiroProvider>{children}</MiroProvider>;

/*
 You can also optional inject the global Miro WebSDK instance
 
 const App: React.FC = ({ children }) => <MiroProvider miro={window.miro}>{children}</MiroProvider>;
*/

Make sure you have a Miro application configured to use it. The hooks in this library will only work within Miro boards and in a well-configured app.

Isomorphic or not?

The Miro WebSDK is NOT isomorphic, meaning that you cannot use it in both server and client environments. This also applies to this library, it won't work wehn you are rendereing your React components in the server.

What if I am using Nextjs?

Using app router

Just make sure that the component that uses the hooks is only rendered on the client by using the use client directive on top of your component.

'use client'
import { useCurrentUser } from "@mirohq/websdk-react-hooks";

// Your component

Using pages router

Wrap your component in a dynamic code block that will defer the component rendering to only execute in the client-side:

import dynamic from "next/dynamic";
import React from "react";
import { useCurrentUser } from "@mirohq/websdk-react-hooks";

const NoSsr: React.FC<React.PropsWithChildren> = (props) => (
  <React.Fragment>{props.children}</React.Fragment>
);

const NoSSRWrapper = dynamic(() => Promise.resolve(NoSsr), {
  ssr: false,
});

// And in your Nextjs page

const Component: React.FC = () => {
    const { status, result, error } = useCurrentUser();

    if (status === "success") {
        return <p>The current user is "{result?.name}"</p>;
    }
}

export default function OnlyInTheClient() {
  return (
    <NoSSRWrapper>
      <Group />
    </NoSSRWrapper>
  );
}

Built with

This library is heavily inspired on https://github.com/react-hookz/web. Pure 💖 awesomeness 💖.

Contributing

Please refer to the CONTRIBUTING.md guide to get started.

Hooks

miro-react-hooks's People

Contributors

fredcido avatar virtuallyawake avatar mettin avatar

Watchers

Anthony Roux avatar Oleg Plotnikov avatar  avatar Yahor Bezzubau avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.