diff --git a/index.js b/index.js index 346b5686b9..0c4778e53d 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,16 @@ import React from 'react'; // import reactDom from 'react-dom'; ---> deprecated import { createRoot } from 'react-dom/client'; +import { Provider } from 'react-redux'; +import { store } from './store'; import App from './src/App'; import './src/style.css'; const container = document.getElementById('root'); const root = createRoot(container); // createRoot(container!) if you use TypeScript // reactDom.render(, document.getElementById('root')); -root.render(); +root.render( + + + +); diff --git a/src/App.jsx b/src/App.jsx index 3ec200e137..7531a34b08 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,4 +1,5 @@ import React, { useState, useEffect } from 'react'; +import { useSelector, useDispatch } from 'react-redux'; import Messages from './components/Messages'; import TextChat from './components/TextChat'; import Nav from './components/Nav'; @@ -12,27 +13,33 @@ const fetcher = (url) => fetch(url).then((res) => res.json()); const postRequest = async (url, { arg }) => await axios.post(url, { arg }); const App = () => { - const [messages, setMessages] = useState([]); - const [convo, setConvo] = useState({ conversationId: null, parentMessageId: null }); + // const [messages, setMessages] = useState([]); + const messages = useSelector((state) => state.messages); + // const [convo, setConvo] = useState({ conversationId: null, parentMessageId: null }); const { data, error, isLoading, mutate } = useSWR('http://localhost:3050/convos', fetcher); - const conversation = useSWRMutation( //{ trigger, isMutating } - `http://localhost:3050/messages/${convo.conversationId}`, - fetcher, - { - onSuccess: function (res) { - console.log('success', res); - setMessages(res); - } - } - ); + const convo = useSelector((state) => state.convo); + const conversationId = useSelector((state) => state.convo.conversationId); + console.log('conversationId', conversationId); - useDidMountEffect(() => conversation.trigger(), [convo]); + // const conversation = useSWRMutation( + // //{ trigger, isMutating } + // `http://localhost:3050/messages/${conversationId}`, + // fetcher, + // { + // onSuccess: function (res) { + // console.log('success', res); + // setMessages(res); + // } + // } + // ); - const onConvoClick = (conversationId, parentMessageId) => { - console.log('convo was clicked'); - setConvo({ conversationId, parentMessageId }); - }; + // useDidMountEffect(() => conversation.trigger(), [conversationId]); + + // const onConvoClick = (conversationId, parentMessageId) => { + // console.log('convo was clicked'); + // setConvo({ conversationId, parentMessageId }); + // }; return (
@@ -40,7 +47,6 @@ const App = () => {