Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react1-week3/anjali #281

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

react1-week3/anjali #281

wants to merge 1 commit into from

Conversation

anjali744
Copy link

No description provided.

@github-actions github-actions bot changed the title react1-week3 Fetch api,adding deadline,updating & bording the component. react1-week3/anjali Apr 2, 2024
Copy link

@BrantalikP BrantalikP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job @anjali744, The app looks good and everything is "kinda of" working, but since Developer experience is important as well, lets please go through the comments and try to address them once you once time :) And as always do not hesitate to reach out to me if you get stuck anywhere. Good luck!

console.log(API_URL)

const App=()=>{
const [json,setjson]=useState([]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the common convention is to jsou always a Capital letter after "set" key, e.g [ json, setJson ] = useState([]) also its not clear what data json holds which can confuse some people, please rename it to todoItems or listData or to something more specific, please :)

fetch(API_URL)
.then((response)=>response.json())
.then((json)=>{
setTimeout(()=>{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. there is no need for setting timeout, the then method is triggered immediately when you receive your response
  2. loading state should be set to true before you start fetching data not after.
  3. it's a good practice not to trigger any anonymous functions inside of useEffect hook. Lets make it clearer what the logic does and lets name it 💪 meaning assigning the function

fetch(API_URL)  
      .then((response)=>response.json())
      .then((json)=>{

to a variable (something like const fetchAndSetListData = fetch ..... ) and then call it below, this will increase the readability :)

<Timer />
</div>
<div>
{loading ? (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want to do the exact opposite :) The loading should be shown when the data is loading not other way around

import {FaCalendarAlt} from 'react-icons/fa';

//function for calender icon
function CustomInput({value,onClick}){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this component to a separate file pls :)

import React, { useState, useEffect } from 'react';
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import 'bootstrap/dist/css/bootstrap.min.css'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job with using bootstrap :) but it's better to import it directly in index.js or App.jsx then you can use it everywhere :) https://react-bootstrap.netlify.app/docs/getting-started/introduction/#css

const [selectedDate, setDate] = useState(new Date());

useEffect(() => {
setTodos(jsonTodos);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can move the whole fetching logic here :) There is no need to have useEffect 2x doing the same thing

checked={todo.completed}
onChange={() => handleCheckboxChange(todo.id)}
/>
<span style={{ marginRight: "10px" }}>{todo.title}</span>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the data from your API does not have title parameter but rather description therefore you cannot see the labels. you should either unify it or you can use || condition to allow both variants {todo.title || todo.descsription}
Screenshot 2024-04-04 at 15 37 12



return (
<div className="todo-container"style={{backgroundColor: "#2FBC8F",width:"80%"}} >

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you are using somewhere className but somewhere else style prop? I think you can style the whole app just using CSS

//function for calender icon
function CustomInput({value,onClick}){
return(
<div className='input-group'>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for better User experience I would attach the onClick={onClick} function to this div, then you will be able to open the calendar by clicking on the calendar icon :)

deadline:selectedDate,
completed: false
};
setTodos([...todos, newTodoItem]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well done 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants