Skip to content

Commit

Permalink
Add readable call for fetch URL
Browse files Browse the repository at this point in the history
  • Loading branch information
punitvara committed Jun 24, 2023
1 parent e659236 commit de3c306
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions UI-app/opinio/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const ENDPOINT = 'http://localhost:8000'; // Your server URL
const App = () => {
const [questions, setQuestions] = useState([]);

const fetchQuestions = () => {
const fetchQuestions = async () => {
console.log('fetchQuestions called');
fetch('http://localhost:8000/questions_details/')
const response = fetch('http://localhost:8000/questions_details/')
.then(response => response.json())
.then(data => {
console.log('Raw data from the backend:', data);
Expand All @@ -27,6 +27,24 @@ const App = () => {
.catch(error => console.error('Error fetching questions:', error));
};

// const fetchQuestions = async () => {
// console.log('fetchQuestions called');
// try {
// const response = await fetch('http://localhost:8000/questions_details/');
// const data = await response.json();
// console.log('Raw data from the backend:', data);
// const fetchedQuestions = data.questions.map(q => ({
// description: q.question_text,
// yesPrice: q.outcome_prices.yes,
// noPrice: q.outcome_prices.no
// }));
// console.log('Updating questions state with:', fetchedQuestions);
// setQuestions(fetchedQuestions);
// } catch (error) {
// console.error('Error fetching questions:', error);
// }
// };

useEffect(() => {
const socket = socketIOClient(ENDPOINT);

Expand Down

0 comments on commit de3c306

Please sign in to comment.