mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-21 19:00:13 +01:00
optimistic ui for message sending and submit state
This commit is contained in:
parent
9d41ed4615
commit
6842ac880c
19 changed files with 430 additions and 92 deletions
18
src/utils/fetchers.js
Normal file
18
src/utils/fetchers.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import axios from 'axios';
|
||||
import useSWR from 'swr';
|
||||
import useSWRMutation from 'swr/mutation';
|
||||
|
||||
const fetcher = (url) => fetch(url).then((res) => res.json());
|
||||
|
||||
const postRequest = async (url, { arg }) => {
|
||||
return await axios.post(url, { arg });
|
||||
};
|
||||
|
||||
export const swr = (path) => useSWR(path, fetcher);
|
||||
|
||||
export default function manualSWR(path, type, successCallback) {
|
||||
const fetchFunction = type === 'get' ? fetcher : postRequest;
|
||||
return useSWRMutation(path, fetchFunction, {
|
||||
onSuccess: successCallback
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue