0.2.1 • Published 6 months ago

@vidog/noreact v0.2.1

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

Lightweight react-like framework

  • Typescript supported
  • JSX supported
  • States
  • Hooks
  • Re-render only updated components

Demo project

Demos

Supported hooks

  • useState
  • useEffect
  • useContext
  • useReference

Installation & Usage

Install requirements for demo

npm install --save-dev typescript ts-loader webpack webpack-cli
npm install @vidog/noreact

Here we use webpack, you can use whatever you want

Create some files

tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "ES5",
        "rootDir": "src",
        "outDir": "dist",
        "jsx": "react",
        "reactNamespace": "JSX"
    }
}

webpack.config.js

const path = require('path')

module.exports = {
    mode: "development",
    devtool: "inline-source-map",
    entry: {
        main: "./src/index.tsx",
    },
    output: {
        path: path.resolve(__dirname, './build'),
        filename: "app.js"
    },
    resolve: {
        extensions: [".ts", ".tsx", ".js", ".jsx"],
    },
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                loader: "ts-loader",
                options: { allowTsInNodeModules: true }
            }
        ]
    }
}

src/index.tsx

import * as NoReact from "@vidog/noreact"
import JSX, {attach, onDomReady, useEffect, useState} from "@vidog/noreact"

interface ButtonProps {
    onclick: (x: any) => void
    children?: NoReact.Component[]
}

function Button(props: ButtonProps): NoReact.Component {
    return (
        <button onclick={props.onclick}>{props.children}</button>
    )
}

function Counter(): NoReact.Component {
    const [counter, setCounter] = useState(0)

    useEffect(() => {
        console.log('[COUNTER]', 'changed to', counter)
    }, [counter])

    const onButtonClick = () => {
        console.log('[CLICK]')

        setCounter(counter + 1)
    }

    return (
        <>
            <p><b>Count:</b> <span style={style}>{counter}</span></p>
            <div>
                <Button onclick={(_) => onButtonClick()}>Click <b>Me</b>!</Button>
            </div>
        </>
    )
}

function App(): NoReact.Component {
    return (
        <div>
            <h1>Hello, world!</h1>
            <Counter />
        </div>
    )
}

onDomReady(() => {
    const root = document.getElementById('root')

    attach(root, <App />)
})

index.html

<html>
    <head>
        <title>NoReact Demo</title>
        <script src="./build/app.js"></script>
    </head>
    <body>
        <div id="root"></div>
    </body>
</html>

Run

npx webpack
open index.html

Building and publishing library

# generate bundle and types
npx tsup lib/lib.ts --dts

# publish library
npm publish --access public
0.2.1

6 months ago

0.2.0

6 months ago

0.1.0

6 months ago

0.0.12

6 months ago

0.0.11

6 months ago

0.0.10

6 months ago

0.0.9

6 months ago

0.0.8

6 months ago

0.0.7

6 months ago

0.0.6

6 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago