NEAR ReactJS Integration

Overview

Description

Prerequisties

Generate Boilerplate Project

Modify Boilerplate App.js

echo "
import 'regenerator-runtime/runtime'
import React from 'react'
import { login, logout } from './utils'
import './global.css'

import getConfig from './config'
const { networkId } = getConfig(process.env.NODE_ENV || 'development')

export default function App() {
  return (
    <p>Hello world!</p>
  );
}
" > ./src/App.js

Modify Boilerplate global.css

echo "
* {
    margin:0;
    padding:0;
}
" > ./src/global.css

Modify Boilerplate src/utils.js

Add React Bootstrap

echo "
import './scss/AppStyles.scss';
import {Navbar, NavDropdown, Nav} from 'react-bootstrap';
`cat ./src/App.js`" > ./src/App.js

Add Navbar

<Navbar collapseOnSelect expand="lg" bg="dark" variant="dark">
    <Navbar.Brand>NEAR-ReactJs Application</Navbar.Brand>
    <Navbar.Toggle aria-controls="responsive-navbar-nav" />
    <Navbar.Collapse id="responsive-navbar-nav">
    <Nav className="me-auto">
    </Nav>
    <Nav>
        <Nav.Link>
        Login
        </Nav.Link>
    </Nav>
    </Navbar.Collapse>
</Navbar>

Add Login Feature

<Nav.Link onclick={
    (window.accountId==='') ?
    login :
    logout
}>
{
    (window.accountId==='') ?
    'Login' :
    'Logout'
}
</Nav.Link>

Creating Metadata

mkdir -p ./src/components; echo "
import {React, useState, useEffect} from 'react';
import {Table} from 'react-bootstrap';
" > ./src/components/Metadata.js