{"id":19164386,"url":"https://github.com/ericdowell/react-endpoint","last_synced_at":"2025-10-06T16:09:24.114Z","repository":{"id":41980865,"uuid":"290090038","full_name":"ericdowell/react-endpoint","owner":"ericdowell","description":"Experimental package that works well with resource-endpoint. Reusable helper functions and experimental components.","archived":false,"fork":false,"pushed_at":"2022-07-04T21:48:23.000Z","size":1787,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-15T14:50:24.589Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericdowell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-25T02:18:56.000Z","updated_at":"2023-11-07T12:55:30.000Z","dependencies_parsed_at":"2022-09-13T21:41:43.318Z","dependency_job_id":null,"html_url":"https://github.com/ericdowell/react-endpoint","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericdowell%2Freact-endpoint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericdowell%2Freact-endpoint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericdowell%2Freact-endpoint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericdowell%2Freact-endpoint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericdowell","download_url":"https://codeload.github.com/ericdowell/react-endpoint/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240245902,"owners_count":19771028,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T09:21:48.771Z","updated_at":"2025-10-06T16:09:19.061Z","avatar_url":"https://github.com/ericdowell.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-endpoint\nExperimental package, preventing re-renders has not been optimized. Some of the helper functions may be of use,\nuse Components with caution.\n\nAdded React.js logic on top of the [resource-endpoint](https://github.com/ericdowell/resource-endpoint) package.\n\n### Examples\n\n### Using RequestForm in React Login Component\n```jsx\n// js/pages/Login.jsx\nimport React from 'react'\nimport { RequestForm, useFormChange } from 'resource-endpoint'\nimport { api } from '../api'\n\nexport const Login = (props) =\u003e {\n    const initialState = {\n        errors: {},\n        email: '',\n        password: '',\n        remember: false,\n    }\n    const [onChange, values, setValues] = useFormChange(initialState)\n    const makeRequest = (inputs) =\u003e api.auth.login(inputs)\n    const onSuccess = ({ user }) =\u003e {\n        if (!user) {\n            setValues({\n                ...values,\n                errors: {\n                    message:\n                        'Something went wrong. Please try again.',\n                },\n            })\n            return\n        }\n        setValues(initialState)\n        props.loginUser(user)\n    }\n    return (\n        \u003cRequestForm makeRequest={makeRequest} onSuccess={onSuccess} setValues={setValues} values={values}\u003e\n            {/* TODO: Error handling, display error messages */}\n            \u003cinput type=\"email\" name=\"email\" value={values.email} onChange={onChange} /\u003e\n            \u003cinput type=\"password\" name=\"password\" value={values.password} onChange={onChange} /\u003e\n            \u003cinput type=\"checkbox\" name=\"remember\" checked={values.remember} onChange={onChange} /\u003e\n            \u003cinput type=\"submit\" value=\"Login\" /\u003e\n        \u003c/RequestForm\u003e\n    )\n}\n```\n\n### Using createStateProvider\n\n```js\n// js/context/index.js\nimport { createStateProvider } from 'react-endpoint'\nimport { api } from '../api'\nimport { fetchCsrfCookie } from '../helpers'\n\nexport const actions = {\n    FLASH_MESSAGE: 'flashMessage',\n    HANDLE_ERROR_MODALS: 'handleErrorModals',\n    PASSWORD_CONFIRMED: 'passwordConfirmedAt',\n    SET_USER: 'user',\n    APP_INITIALIZE: 'initialized',\n    SHOW_AUTHENTICATE_MODAL: 'mustAuthenticate',\n    SHOW_CONFIRM_PASSWORD_MODAL: 'mustConfirmPassword',\n}\n\nexport const [Context, StateProvider] = createStateProvider({\n    initialState: {\n        flashMessage: null,\n        initialized: false,\n        mustAuthenticate: false,\n        mustConfirmPassword: false,\n        passwordConfirmedAt: window.demo.passwordConfirmedAt,\n        user: window.demo.user,\n    },\n    actions,\n    providerHelpers: (dispatch) =\u003e ({\n        /**\n         * Helper function that reduces effort to call Reducer dispatch function.\n         *\n         * @param {string} action\n         * @param {*} payload\n         * @returns {void}\n         */\n        dispatchAction: function (action, payload) {\n            return dispatch({ type: action, [action]: payload })\n        },\n\n        /**\n         * TODO: Modals sometimes create re-renders, this is not great, maybe there's\n         *       another way to prevent this by using a different global state.\n         *\n         * Handle showing a modal in specific error cases.\n         *\n         * @param {*} payload\n         * @returns {void}\n         */\n        modal: function (payload) {\n            return this.dispatchAction(actions.HANDLE_ERROR_MODALS, payload)\n        },\n\n        /**\n         * Initialize user globally.\n         *\n         * @returns {void}\n         */\n        initializeUser: function () {\n            api.user.current().then((response) =\u003e {\n                if (response.status === 200) {\n                    this.setUser(response.data.user)\n                } else if (response.status !== 401) {\n                    window.console.error('error when calling user.current()', response)\n                }\n                this.dispatchAction(actions.SHOW_AUTHENTICATE_MODAL, false)\n                this.dispatchAction(actions.APP_INITIALIZE, true)\n            })\n        },\n\n        /**\n         * Set user globally.\n         *\n         * @param {*} user\n         * @returns {void}\n         */\n        setUser: function (user) {\n            // NOTE: Need to get a new (valid) CSRF Cookie after user has been logged out.\n            if (!user) {\n                fetchCsrfCookie()\n            }\n            return this.dispatchAction(actions.SET_USER, user)\n        },\n\n        /**\n         * Flashing a message on pages that support it.\n         *\n         * @param {string} message\n         * @param {number} timeout\n         * @returns {void}\n         */\n        flash: function (message, timeout = 3000) {\n            // TODO: Add slow css transition to fade out text\n            setTimeout(() =\u003e this.dispatchAction(actions.FLASH_MESSAGE, null), timeout)\n            return this.dispatchAction(actions.FLASH_MESSAGE, message)\n        },\n    }),\n})\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericdowell%2Freact-endpoint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericdowell%2Freact-endpoint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericdowell%2Freact-endpoint/lists"}