0.2.18 • Published 1 year ago

react-fcomponents v0.2.18

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

React-fcomponents

Use classes as functional React components.

Example of usage:

import { useEffect, useState } from "react";
import FComponent, { make } from "react-fcomponents";

class ExampleClass extends FComponent {
    useTest = (...args) => {
        useEffect(() => {
            console.log('mounted');
        }, []);
        return useState(...args);
    }

    useHooks() {
        this.useTest();
        this.useState('test', 0);
    }

    render(props) {
        return <div>{this.props.text}<button onClick={
            () => {
                this.setStates.test(this.states.test + 1)
            }
        }>{this.states.test}</button></div>;
    }

}

export default make(ExampleClass);

You must export make(ExampleClass), not just ExampleClass.

In render you can write anything like in functional component. You can use props or this.props.

useHooks runs before render, you can add hooks to this.

this.useState(<key>, <default value>) - create state with name key. You can use this.states.<key> and this.setStates.<key>() after it.

0.2.18

1 year ago

0.2.16

1 year ago

0.2.14

1 year ago

0.2.12

1 year ago

0.2.10

1 year ago

0.2.8

1 year ago

0.2.6

1 year ago

0.2.4

1 year ago

0.2.2

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago