Skip to content

Commit a639a85

Browse files
committed
Reactjs supported libraries questions
1 parent f903e16 commit a639a85

File tree

1 file changed

+92
-8
lines changed

1 file changed

+92
-8
lines changed

README.md

Lines changed: 92 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@ Below is a list of ReactJS interview questions and answers.
189189
|180| [Why is react component's constructor called once?](#why-is-react-component's-constructor-called-once)|
190190
|181| [How to define constants in reactjs?](#how-to-define-constants-in-reactjs)|
191191
|182| [How to programmatically trigger click event in reactjs?](#how-to-programmatically-trigger-click-event-in-reactjs)|
192-
|183| [](#)|
193-
|184| [](#)|
194-
|185| [](#)|
195-
|186| [](#)|
196-
|187| [](#)|
197-
|188| [](#)|
198-
|189| [](#)|
192+
|183| [Is it possible to use async/await in plain react?](#is-it-possible-to-use-async/await-in-plain-react)|
193+
|184| [How to pass numbers to components?](#how-to-pass-numbers-to-components)|
194+
|185| [What are styled components?](#what-are-styled-components)|
195+
|186| [Give an example of styled components?](#give-an-example-of-styled-components)|
196+
|187| [What is Relay?](#what-is-relay)|
197+
|188| [How Relay is different from Redux?](#how-relay-is-different-from-redux)|
198+
|189| [What are the common folder structures for react?](#what-are-the-common-folder-structures-for-react)|
199199
|190| [](#)|
200200
|191| [](#)|
201201
|192| [](#)|
@@ -2731,4 +2731,88 @@ You could use the ref prop to acquire a reference to the underlying HTMLInputEle
27312731
```
27322732
this.inputElement.click();
27332733
```
2734-
###
2734+
### Is it possible to use async/await in plain react?
2735+
React Native ships with Babel and some Babel presets, whereas React on the web is just React related code. f you want to use async/await on the web then either
2736+
1. You'll need Babel and the correct transforms
2737+
https://babeljs.io/docs/plugins/transform-async-to-generator/
2738+
2. Use stage-1 presets which is fairly common in React apps
2739+
https://babeljs.io/docs/plugins/transform-async-to-generator/
2740+
### How to pass numbers to components?
2741+
You should be passing the numbers via curly braces({}) where as strings inn quotes
2742+
```
2743+
React.render(<User age={30} department={"IT"} />, document.getElementById('container'));
2744+
```
2745+
### What are styled components?
2746+
Styled-components is a JavaScript library for styling React applications. It removes the mapping between styles and components, and lets you write actual CSS augmented with JavaScript.
2747+
### Give an example of styled components?
2748+
Lets create Title and Wrapper components with specific styles for each.
2749+
```
2750+
import React from 'react';
2751+
import styled from 'styled-components';
2752+
2753+
// Create a <Title> react component that renders an <h1> which is centered, red and sized at 1.5em
2754+
const Title = styled.h1`
2755+
font-size: 1.5em;
2756+
text-align: center;
2757+
color: palevioletred;
2758+
`;
2759+
2760+
// Create a <Wrapper> react component that renders a <section> with some padding and a papayawhip background
2761+
const Wrapper = styled.section`
2762+
padding: 4em;
2763+
background: papayawhip;
2764+
`;
2765+
```
2766+
These two variables, Title and Wrapper, are now a React components you can render like any other React component
2767+
```
2768+
<Wrapper>
2769+
<Title>Lets start first styled component!</Title>
2770+
</Wrapper>
2771+
```
2772+
### What is Relay?
2773+
Relay is a JavaScript framework for providing a data layer and client-server communication to web applications using the React view layer.
2774+
### How Relay is different from Redux?
2775+
Relay is similar to redux in that they both use a single store. The main difference is that relay only manages state originated from the server, and all access to the state is used via GraphQL querys (for reading data) and mutations (for changing data). Relay caches the data for you and optimizes data fetching for you, by fetching only changed data and nothing more.
2776+
### What are the common folder structures for react?
2777+
Basically there are two common practices for reactjs file structure
2778+
1. **Grouping by features or routes**
2779+
One common way to structure projects is locate CSS, JS, and tests together inside folders grouped by feature or route.
2780+
```
2781+
common/
2782+
Avatar.js
2783+
Avatar.css
2784+
APIUtils.js
2785+
APIUtils.test.js
2786+
feed/
2787+
index.js
2788+
Feed.js
2789+
Feed.css
2790+
FeedStory.js
2791+
FeedStory.test.js
2792+
FeedAPI.js
2793+
profile/
2794+
index.js
2795+
Profile.js
2796+
ProfileHeader.js
2797+
ProfileHeader.css
2798+
ProfileAPI.js
2799+
```
2800+
2. **Grouping by file type**
2801+
Another popular way to structure projects is to group similar files together
2802+
```
2803+
api/
2804+
APIUtils.js
2805+
APIUtils.test.js
2806+
ProfileAPI.js
2807+
UserAPI.js
2808+
components/
2809+
Avatar.js
2810+
Avatar.css
2811+
Feed.js
2812+
Feed.css
2813+
FeedStory.js
2814+
FeedStory.test.js
2815+
Profile.js
2816+
ProfileHeader.js
2817+
ProfileHeader.css
2818+
```

0 commit comments

Comments
 (0)