Implement a Collaborative Textbox

Our application is based on ReactJS, which is a famous Javascript library for building user interfaces. We also use Create-React-App to create our single-paged application.

With Create-React-App, our folder structure would be like:

my-app/
  README.md
  node_modules/
  package.json
  public/
    index.html
    favicon.ico
  src/
    App.css
    App.js
    App.test.js
    ClickToEdit.js
    index.css
    index.js
    logo.svg
    reportWebVitals.js
    setupTests.js

And it is exactly how our workspace /App is organized.

App.js

We chose React as our framework because its idea of "Componentsarrow-up-right" greatly enables us to implement our collaborative textbox as an independent, reusable piece that can be plugged into a webpage with a single line of code, an example is already in App.js:

In the function of App, we created three instances of the textbox, each is specified with a unique room name, and has a Y.doc() to store its content. Y.doc is the shared document data structure provided by Yjs.

You can add as many ClickToEdit components as you like.

ClickToEdit.js

The component ClickToEdit is implemented in ClickToEdit.js. Here we utilized React's hooks to build the WebSocket connection and implement the toggled button to connect and disconnect.

Last updated