Let's Add File Sharing


  • React 16.8 or higher
  • Weavy 8.2 or higher

You may also integrate Weavy into an existing app instead of creating a new app, just skip the create a new react app step.

Create a new react app using NPX

NPX is the script manager that comes with Node and NPM, which you may use to create a new react app. React will recommend you to use yarn or npm depending on if you have yarn installed or not.

npx create-react-app weavy-react-app

cd weavy-react-app

yarn start

This will build and launch the dev server, usually on http://localhost:3000

Add the Weavy Script

The simplest way to add the Weavy script is to just add it to the head section in the public/index.html. Replace {your-server-domain} with the domain name of your own Weavy server.




    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

    <script src="https://{your-server-domain}/javascript/weavy.js"></script>


Create a shared Weavy context

To be able to link the Weavy instance to Weavy apps without passing down properties we take advantage of a shared state using a shared context. The Weavy instance component will act as the provider and the Weavy app component as the consumer. Create a new file src/weavy/WeavyContext.js to hold the shared context.


import React from 'react';

export default React.createContext();

Create a Weavy instance component

To optimize performance we use a common Weavy instance in a component src/weavy/Weavy.js. The instance is linked to the Weavy app using the Weavy context. To provide authentication, we prepare the instance to connect a JWT token provider from a property. We delay the initialization to provide recommended creation and cleanup.


import { Component } from 'react';

import './Weavy.css';

import WeavyContext from './WeavyContext';

export default class Weavy extends Component {

    constructor(props) {


        this.state = { weavy: new window.Weavy({ jwt: props.jwt, init: false })};


    componentDidMount() {



    componentWillUnmount() {



    render() {

        return <WeavyContext.Provider value={this.state}>{this.props.children}</WeavyContext.Provider>;



Create a Weavy App component

The Weavy App component src/weavy/WeavyApp.js will define a Weavy space, then define the Weavy app in a div. The Weavy instance will be referenced from the consumed context. The space and file sharing app are defined from component properties.

Spaces are used in Weavy to group apps around a subject or entity. Within those spaces are members. Any members within a space have access to any apps within that space.

In order to set up the Weavy space, we need a unique identifier - the key. Keys must be unique because they are used to grab the contextual information for that specific space or app. Any unique identifier will do - it just can't be too long.

Learn more about spaces - Spaces & Client Structure


import { Component } from 'react';

import './Weavy.css';

import WeavyContext from './WeavyContext';

export default class WeavyAppextends Component {

    static contextType = WeavyContext;

    async createWeavyApp() {

        this.weavySpace = this.weavy.space({

            key: this.props.spaceKey,

            name: this.props.spaceName


        this.weavyApp = this.weavySpace.app({

            key: this.props.appKey,

            type: this.props.appType,

            name: this.props.appName,

            container: this.el



    componentDidMount() {

        this.weavy = this.context.weavy;




        // A key must change for the app to change

        var spaceChanged = nextProps.spaceKey !== this.props.spaceKey;

        var appChanged = nextProps.appKey !== this.props.appKey;

        return spaceChanged || appChanged;


    componentDidUpdate(prevProps) {




    componentWillUnmount() {



    render() {

        return <div className="weavy-container" ref={el => this.el = el} />;



Style the Weavy container

Weavy apps will automatically size themselves to the container, so we need to set a size on the Weavy container. Set the height in a stylesheet src/weavy/Weavy.css


.weavy-container {

    height: 300px;


Using the Weavy components

The Weavy instance component is only used as a wrapper. You can put it anywhere in your app and you may use multiple instances if you like. The important thing is to place the Weavy app component anywhere inside the wrapper. Import the components in your src/App.js and use the components. You also need to define a JWT token provider and set it as a property on the Weavy instance component.

See Docs - Client Authentication to read more about setting up JWT authentication.

JWT Token must be set up correctly with exp, iss, sub, and the client secret in order for Weavy to work

Both the Weavy Component and the WeavyApp Component will clean up themselves when removed.


import { Component } from 'react';

import './App.css';

import Weavy from './weavy/Weavy';

import WeavyApp from './weavy/WeavyApp';

export default class App extends Component {

    async getJwt() {

        return '[Provide your JWT here]';


    render() {

        return (

            <Weavy jwt={this.getJwt}>

                <div className="App">



                        spaceName="React Space"


                        appName="React Files"








That's it!

Now you have a fully customizable Weavy Files component to integrate anywhere in your React web app!