1.0.44 • Published 1 year ago

reactbootdev v1.0.44

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

reactbootdev

npm npm version npm downloads

Project Overview

The objective is to develop Reactjs with a focus on entity-centric architectures, boosting productivity and smoothly linking it with JPA to facilitate effective CRUD operations. This project manages validation, transformation, and communication with the server through entities.

Features

Installation

bash

  • Install typescript, reactjs project
npx create-react-app my-app --template typescript
  • Install dependencies
npm i reactbootdev
npm i react-router-dom axios recoil uuid env-cmd lodash
npm i @mui/material @emotion/react @emotion/styled
npm i @craco/craco craco-alias
npm i styled-components 

# `@tanstack/react-query`
npm i @tanstack/react-query
# `react-hook-form`
npm i react-hook-form
# `class-transformer`
npm i class-transformer reflect-metadata es6-shim
# `class-validator`
npm i class-validator
  • Install dev dependencies
npm install -D nodemon
npm install --save-dev @types/uuid

tsconfig.json

{
  "extends": "./tsconfig.paths.json",
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "baseUrl": "src",
    "paths": {
      "@src/*": [
        "./*"
      ],
      "@components/*": [
        "components/*"
      ],
      "@utils/*": [
        "utils/*"
      ]
    },
    // ...
  },
  "include": [
    "src",
    "craco.config.js"
  ]
}

tsconfig.paths.json

{
  "compilerOptions": {
    "baseUrl": "./",
    "paths": {
      "@src/*": [
        "src/*"
      ]
    }
  }
}

craco.config.js

const CracoAlias = require("craco-alias");

module.exports = {
    plugins: [
        {
            plugin: CracoAlias,
            options: {
                source: "tsconfig",
                tsConfigPath: "tsconfig.paths.json",
            },
        },
    ],
};

.env.production, .env.development

  • Create blank files in root directory

.gitignore

# reactbootdev
src/reactbootdev

package.json

  • Adjust scripts for reactbootdev, nodemon, env-cmd, craco
  "scripts": {
    "rt": "npx reactbootdev",
    "rtstart": "npm run rt && npm run start",
    "rtbuild": "npm run rt && npm run build",
    "rtnodemon": "nodemon -V --watch src --ext js,mjs,cjs,json,jsx,ts,tsx --delay 5000ms --exec \"npm run rt\"",
    "build": "env-cmd -f .env.production craco build",
    "start": "env-cmd -f .env.development craco start",
    "test": "craco test",
    "eject": "react-scripts eject"
  },

App.tsx

import React from 'react';
import {ReactBoot} from "@src/reactbootdev/component/ReactBoot";

function App() {
    return (
        <div className="App">
            <ReactBoot/>
        </div>
    );
}

export default App;

Usage

Page

@page

  • Add @page("/url") to class
MyPage.tsx
  • Simple page
import React from "react";
import {page} from "@src/reactbootdev/decorator/page";

@page("/")
export class MyPage  {
    render() {
        return (
            <div>
                <h1>My Page</h1>
            </div>
        );
    }
}
WelcomePage.tsx
  • Page with function component
import React from "react";
import {page} from "@src/reactbootdev/decorator/page";

export function WelcomeComponent() {
    return (
        <div>
            <h1>Welcome</h1>
        </div>
    )
}

@page("/")
export class Welcome {
    render() {
        return <WelcomeComponent/>;
    }
}

Entity

@entity

  • Add @entity to class
src/entity/ProjectEntity.ts
import {entity} from "@src/reactbootdev/decorator/Entity";
import BaseEntity from "@src/reactbootdev/entity/BaseEntity";

@entity
export class ProjectEntity extends BaseEntity {
    id: number | null = null;
    name?: string
    description?: string
    startDate?: string
    endDate?: string
}

Repository

  • Recoil Based Repository
src/repository/ProjectRepository.ts
import BaseRepository from "@src/reactbootdev/repository/BaseRepository";
import {v4 as uuidv4} from 'uuid';
import {ProjectEntity} from "@src/entity/Project";

export class ProjectRepository extends BaseRepository<ProjectEntity> {
    static defaultRepositoryKey = uuidv4()
    static defaultEntityClass = ProjectEntity;
}
src/component/CreateComponent.tsx
  • Single Entity
import {ProjectRepository} from "@src/repository/ProjectRepository";
import {ProjectEntity} from "@src/entity/Project";

const CreateComponent = () => {
    const repo = useRepository(ProjectRepository);

    useEffect(() => {
        const defaultEntity = new ProjectEntity()
        defaultEntity.name = "test"
        
        repo.setEntity(defaultEntity)
    }, [])
    
    return (
        <>
            {JSON.stringify(repo.getEntity())}
        </>
    );
}
  • Multiple Entity
import {ProjectRepository} from "@src/repository/ProjectRepository";
import {ProjectEntity} from "@src/entity/Project";

const CreateComponent = () => {
    const repo = useRepository(ProjectRepository);

    useEffect(() => {
        const defaultEntity = new ProjectEntity()
        defaultEntity.name = "test"
        const defaultList = [defaultEntity, defaultEntity]
        
        repo.setList(defaultList)
    }, [])
    
    return (
        <>
            {JSON.stringify(repo.getList())}
        </>
    );
}

Api

  • ReactQuery Based Api

Form

  • ReactHookForm Based Form

bash

npm run rtstart

Samples

Take a look on samples in ./src/test/reactjs for more examples of usages.

Release notes

See information about breaking changes and release notes here.

1.0.44

1 year ago

1.0.43

1 year ago

1.0.42

1 year ago

1.0.41

1 year ago

1.0.40

1 year ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago