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

Update react.md #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 6 additions & 39 deletions react.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,27 @@

<details>
<summary>What are the pre requesites(excluding the general HTML, CSS, and JS) before starting off with React?</summary>

Apart from HTML, CSS and a good level of comfort with Javascript, learning react requires one to be be familiar with Object Oriented Concepts since React uses a lot of inheritance from classes and methods that are used to create both functional and presentational components. Knowledge of Single Page Applications is also important as it will give you an idea of how routing happens with the understanding that the routes are dynamic and not physical pages on the server. To set up you can either use a [script tag](https://reactjs.org/docs/add-react-to-a-website.html) that pulls in React in your project or to set up using [create-react-app](https://github.com/facebook/create-react-app) from Facebook. You can then write your own React code in a simple JS file for functional components and JSX file for presentational components.

You can start with the official docs' [getting started](https://reactjs.org/docs/getting-started.html) page which are very beginner friendly.

React is one of the most simple and powerfull tech out there. Most of the doc is written with ES6 so I suggest to pick it up.
</details>

----

<details>
<summary>Why do we need hooks?</summary>

Hooks are a way of letting the developer use State or other React Features without necessarily writing class components (sounds cool, right?!). Previously React required that to create state or set State of a component on needs to declare a class component where the state could be initialized and then would be later used in the class component. Using React hooks one can easily initialize state or any lifecycle methods within functional components. An example would be setting initial state of counter in a functional component and incrementing the counter as a button is clicked.

```
import { useState } from 'react';

function Example() {
// Declare a new state variable, which we'll call "count"
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}

```
From the above the `useState` is the hook which we use to initialize our state, to trigger the hook we call the function that we declare while initializing the react hook which is `setCount`. It is important to note that the hook will only be used with the initial state and will only work withing react functional components.

Hooks were created to share state logic across components. As a conseguence of that algorithm that were splitted across different lifecycle method are now more easy to read.
</details>

----
--------

<details>
<summary>Why can’t we use variables/functions directly inside a function component?</summary>

If you know the answer to this question, please submit a pull request with the answer.

of course we can.
</details>

_Waiting for response_


----
--------

<details>
<summary>What are React render props?</summary>

If you know the answer to this question, please submit a pull request with the answer.

Props are the React way to pass variable. They can be functions, components, primitive types.
</details>

_Waiting for response_