3.0.6 • Published 1 year ago

context-base-api v3.0.6

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

context-base-api

This is library help u with solve problem with rerenders and simplify DI to your pages.

Basic Usage

take the next.js page as an example

import { withContexts } from "context-base-api";

export default withContexts(TodoPage, [GlobalStore])

and also use our store in the component we need

import { FC, PropsWithChildren } from "react";
import { connectContext } from "context-base-api";

export const TodoList = connectContext(
    [GlobalStore],
    ([{ notifications, todos }]) => ({ todos })
)(({ todos }) => {
    return (
        <div>
            {todos.map(({ name }) => (
                <div>{name}</div>
            ))}
        </div>
    );
});

Stores

Create simple store

export const MessagesStore = createStore(() => {
    const [loading, setLoading] = useState(false);
    const [data, setData] = useState<string[]>();

    const loadingItems = () => {
        setLoading(true);
        (() => {
            setData([]);
        })();
        setLoading(false);
    };

    return {
        state: { messages: { isLoading: loading, items: data } },
        actions: { loadingItems },
    };
});

Create store with dependencies another store

export const MessagesStore = createStore(({notifications}) => {
    const [loading, setLoading] = useState(false);
    const [data, setData] = useState < string[] > ();

    const loadingItems = () => {
        setLoading(true);
        (() => {
            setData([]);
        })();
        setLoading(false);
    };

    return {
        state: {messages: {isLoading: loading, items: data}},
        actions: {loadingItems},
    };
}, [GlobalStore.Context], 
    ({state: {notifications}}) => ({ notifications})
);

Contribution

In the near future I would like to add several Contexts for use in connectContext. If you have time you can help me with this

Donation

Donation Alerts

3.0.6

1 year ago

3.0.5

1 year ago

3.0.4

1 year ago

3.0.3

1 year ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

2.0.10

1 year ago

2.0.9

1 year ago

2.0.8

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago