Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Responsive Notifications Page Using React, CSS Fflexbox, CSS Grid

@ereljapco

Desktop design screenshot for the Notifications page coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


I just learned how to use the useState, but I wasn't sure if I had used it wisely.

Questions:

  1. If I have imported a data list (notificationsList.js in this case) in the App.js, can I just pass it on as a prop or is it better to import it on the component? Does having the useState in the App.js as the parent affect this decision?

I hope someone can review my code which can be found here and let me know how I can improve on using it.

Thank you so much! :)

Community feedback

tan 640

@tan911

Posted

It's okay to import 'notificationList' directly to the component's who needs it. Also you can pass 'notificationList' as props. However when passing it as props I think it's read not a notificationList, the code looks like this,

import Header from './components/header/Header';
import Notifications from './components/notifications/Notifications';
import notificationsList from './data/notificationsList';

export default function App() {
  const [read, setRead] = useState(notificationsList);

  return (
    <main className="main">
      <section className="notifications">
        <div className="c-notifications">
          <Header setRead={setRead}  notificationsList={read} />
          <Notifications />
        </div>
      </section>
    </main>
  );
}

You use 'useState' with initial value of 'notificationsList'. You don't need to pass 'notificationList' itself instead use the 'read' variable to pass data into your children component.

Marked as helpful

1

@ereljapco

Posted

Oh, right. Forgot about the initial value. Thank you, @tan911! ☺ By the way, can I ask which is the best practice in this case? Passing the initial value as props or importing it on the component?

0
tan 640

@tan911

Posted

@ereljapco Welcome, Importing on the component is even better.

1

@ereljapco

Posted

@tan911 Thank you so much! I will refactor my code using import then ☺

1

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord