Day 7 on Redesigning Nasa's Picture of the Day webpage
Tags: react, opensource, typescript, api
Published: 2022-03-11 05:00:57

Hello once again! I'll make this more straight forward

## 📚 What I have learned for this whole time

Components in React are really functions in javascript where you can easily separate a portion of the whole project into a piece where you can read the code in either it's own file or on the default '/App.js' file which makes your code more clear to you and where they are meant to go. This is pretty well know and if you have been following along reading the code, you will also know that I have separated the main components into it's own file and directory as it does give me a peace of mind. 

Now, I'll be going over props. What are props? How can I use them?

For those already in the programming scene, it is similar to this.blank (definitely in javascript) or self.blank (You can find this in Python), where the inputs of the user or developer will go into that function through props. First off, you do not need to type in certain content to everything in every place. With props you can make objects of an account or props of the current date. Heres what I mean. 

```typescript
function Content(props) {
  return (
    // Insert your code
    <h1>My name is {props.name}</h1>
  )
}

function App() {
 return (
    <>
      <Content name="Jordon" />
      <Content name="Samuel" />
      <Content name="Peter" />
    </>
  )
}
```

I have learnt how to add the correct time on a blank React project, and I think it was javascript too, but the types are not an issue or something to worry about now. There was a lot learnt from that especially on the ways it can be used. If you want to see more on how this is done [click here](https://codepen.io/gaearon/pen/VKQwEo?editors=1010).

## 🚀 States
A state is when the output of something is changed in real time, and will update depending on the code or any imported library that has a state. On [Reactl.org](https://reactjs.org/docs/state-and-lifecycle.html), you can find the clock example in there and see the code on how it looks like. Here is what it looks like in case you don't want to look at it on the website:

```javascript
function tick() {
  const element = (
    <div>
      <h1>Hello, world!</h1>
      <h2>It is {new Date().toLocaleTimeString()}.</h2>
    </div>
  );
  ReactDOM.render(
    element,
    document.getElementById('root')
  );
}

setInterval(tick, 1000);
```

Heres what it looks like with props:

```javascript
function Clock(props) {
  return (
    <div>
      <h1>Hello, world!</h1>
      <h2>It is {props.date.toLocaleTimeString()}.</h2>
    </div>
  );
}

function tick() {
  ReactDOM.render(
    <Clock date={new Date()} />,
    document.getElementById('root')
  );
}

setInterval(tick, 1000);
```

## 🛫 API
I have been watching this tutorial to APIs by [FreeCodeCamp](https://www.youtube.com/watch?v=GZvSYJDk-us). I'll be learning from it and soon apply it to this very project and also continue to post more often. {% embed https://www.youtube.com/watch?v=GZvSYJDk-us %}

---

Thank you so much for reading this post as I did have a chance to make this post a few days ago, but I didn't do it because I procrastinated. It sucks but I'm back at it again.
I have provided some links down below. 

* [APOD Repository](https://github.com/H12M54AM/nasa-astronomy-webpage)
* [My Github](https://github.com/H12M54AM)
* [Twitter](https://twitter.com/EWNaidoo)

Hope to see you again soon!

---

## ⚙️ Resources

* [Components and Props - reactjs.org](https://reactjs.org/docs/components-and-props.html)
* [Heres the CodePen with props](https://codepen.io/gaearon/pen/VKQwEo?editors=1010)
* [State - reactjs.org](https://reactjs.org/docs/state-and-lifecycle.html)