├── Questions and Exercises ├── 1. Getting started with React │ └── Questions.txt ├── 10. Building a blog with Hooks │ └── Questions and Answers.txt ├── 11. Styling in React │ └── Questions.txt ├── 12. Major Project Setup and Intro │ └── Questions.txt ├── 13. React Hooks │ └── Questions.txt ├── 14. Building a blog with Hooks │ └── Questions.txt ├── 15. Styling in React │ └── Questions.txt ├── 16. Major Project Setup and Intro │ └── Questions.txt ├── 17 Major Project Routing and Auth │ └── Questions.txt ├── 18. Major Project User profile │ └── Questions.txt ├── 19. Major Project Search and Chat │ └── Questions.txt ├── 2. Warm up Javascript │ └── Questions.txt ├── 20. Intro to Redux │ └── Questions.txt ├── 21. Redux Actions, Reducers, Store │ └── Questions.txt ├── 22. Redux Continued │ └── Questions.txt ├── 23. React and Redux │ └── Questions.txt ├── 3. Hello World │ └── Questions and Answers.txt ├── 4. Mini Project Starting the project(Shopping Cart) │ └── Questions.txt ├── 5. Mini Project Managing state │ └── Questions.txt ├── 6. Mini Project Finishing up │ └── Questions.txt ├── 7. Firebase Mini Project extended I │ └── Questions.txt ├── 8. Firebase Mini project extended II │ └── Questions.txt └── 9. React Hooks │ └── Questions.txt └── Readme.md /Questions and Exercises/1. Getting started with React/Questions.txt: -------------------------------------------------------------------------------- 1 | 1. React is a _____ ? 2 | ans: javascript library. 3 | 4 | Solution Description 5 | ReactJS is a javascript library for building user interfaces. It's not a framework. 6 | A library is basically used to solve some common problems, we don't have to write code in Vanilla JS that is pure JS that could be somewhat challenging for people. 7 | That means, in order to build complete React applications, you will need to choose the packages and tools on your own. 8 | While Angular is usually considered a framework as it provides strong opinions on how your application should be structured. 9 | 10 | 2. What are the advantages of using React ? 11 | ans: 12 | 1. React has reusable components: Code re-use helps make your apps easier to develop and easier to maintain. They also help you implement a consistent look and feel across the whole project. 13 | 2. React improves performance due to VDOM. 14 | 15 | 3. Which terminal command is used to remove the directory? 16 | ans: rmdir is used to remove a directory. 17 | 18 | 4. Write a command to move one level up from the current directory? 19 | ans: cd 20 | Solution Description 21 | cd is used to change the directory. It is used to navigate directly to a directory, use cd with the directory’s path as an argument. 22 | 23 | 5. What is a React in a MVC architecture? 24 | ans: View. 25 | Solution Description 26 | React is the view part of the MVC framework. It is an open-source javascript library that provides a view for the data rendered as HTML. 27 | 28 | 6. Which command is used to print the current working directory? 29 | ans: pwd. 30 | 31 | 7. Write command to move the directory one level up from the current directory. 32 | ans: cd .. 33 | 34 | 8. React.js was orginally created by? 35 | ans: Jordan Walke. 36 | 37 | 9. How is Real DOM different from Virtual DOM? 38 | ans: 39 | Manipulating the real DOM is slow. Manipulating the virtual DOM is much faster. 40 | A virtual DOM object is a representation of a DOM object, like a lightweight copy. 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Questions and Exercises/10. Building a blog with Hooks/Questions and Answers.txt: -------------------------------------------------------------------------------- 1 | 1. Get firebase data 2 | Send Feedback 3 | How would you get multiple documents from firestore? 4 | ans: db.collection("posts").get(). 5 | Solution Description 6 | There are two ways to retrieve data stored in Cloud Firestore. Either of these methods can be used with documents, collections of documents, or the results of queries: 7 | - Call a method to get the data. 8 | - Set a listener to receive data-change events. 9 | 10 | Read More: https://firebase.google.com/docs/firestore/query-data/get-data 11 | 12 | 2. Order by 13 | Send Feedback 14 | How to order posts by likes? 15 | ans: postsRef.orderBy("likes", "desc"); 16 | Solution Description 17 | By default, a query retrieves all documents that satisfy the query in ascending order by document ID. You can specify the sort order for your data using orderBy(). 18 | 19 | Read More: https://firebase.google.com/docs/firestore/query-data/order-limit-data 20 | 21 | 3. Custom hooks 22 | Send Feedback 23 | Which of the following is a custom hook? 24 | ans: function useOpenPopup(){} 25 | Solution Description 26 | Name of a custom hook should always start with "use". 27 | 28 | 4. Sharing state 29 | Send Feedback 30 | Do two components using the same Hook share state? 31 | ans: No 32 | Solution Description 33 | Custom Hooks are a mechanism to reuse stateful logic (such as setting up a subscription and remembering the current value), but every time you use a custom Hook, all state and effects inside of it are fully isolated. 34 | 35 | 5. Create React App 36 | Send Feedback 37 | Which command is correct for creating a react project? 38 | ans: npx create-react-app foldername. 39 | Solution Description 40 | It sets up your development environment so that you can use the latest JavaScript features, provides a nice developer experience, and optimizes your app for production. npx is a package runner tool that comes with npm 5.2+. 41 | 42 | 6. Importing in React 43 | Send Feedback 44 | Which of the following is the correct syntax for importing BrowserRouter from “react-router-dom” ? 45 | ans: import {BrowserRouter} from "react-router-dom" 46 | Solution Description 47 | Every module can have several named parameters and in order to import one we should enclose named parameters within the curly braces. 48 | 49 | 7. Exporting in React 50 | Send Feedback 51 | Which of the following syntax is correct for exporting more than one component? 52 | ans: export {App, Navbar, Home, CreatePost, PostDetail} 53 | Solution Description 54 | For multiple exports, we can use a comma to separate two-parameter names within the curly braces. 55 | 56 | 8. React router DOM 57 | Send Feedback 58 | _________ Provides declarative, accessible navigation around your application. 59 | ans: 60 | Solution Description 61 | As you click around on the different s, the router renders the matching . 62 | Read More: https://reactrouter.com/web/api/Link 63 | 64 | 9. Fill Up 65 | Send Feedback 66 | The ________________ method is used to prevent the browser from executing the default action of the selected element. 67 | ans: preventDefault(). 68 | Solution Description 69 | The preventDefault() method cancels the event if it is cancelable, meaning that the default action that belongs to the event will not occur. 70 | For example, clicked anchors will not take the browser to a new URL. 71 | 72 | 10. Custom Hooks 73 | Send Feedback 74 | True/False 75 | custom hooks improves the readability and a reduces the amount of code. 76 | ans: True. 77 | Solution Description 78 | Custom Hooks are a mechanism to reuse stateful logic (such as setting up a subscription and remembering the current value), but every time you use a custom Hook, all state and effects inside of it are fully isolated. So, it improves the readability and reduces the amount of code. 79 | 80 | 11. Fetch data 81 | Send Feedback 82 | ____________ function is used to fetch data from the firebase. Document. 83 | ans: onSnapshot(). 84 | 85 | 12. URL Parameters 86 | Send Feedback 87 | _________ hooks let you access the parameters of the current route 88 | ans: useParams. 89 | Solution Description 90 | In React Router, we use the word "params" to describe dynamic segments of the URL. useParams hooks let you access the parameters of the current route. 91 | 92 | 13. Which command is used for deploying a firebase-hosted application? 93 | ans: firebase deploy. 94 | 11. Firebase 95 | Send Feedback 96 | Firebase is a 97 | ans: NoSql Database. 98 | Realtime Database. 99 | Cloud-Hosted Database. 100 | Solution Description 101 | Firebase Real-Time Database is a cloud-hosted and NoSQL database. Data is stored as JSON and synced in real-time for each connected client. -------------------------------------------------------------------------------- /Questions and Exercises/11. Styling in React/Questions.txt: -------------------------------------------------------------------------------- 1 | 1. CSS modules 2 | Send Feedback 3 | CSS modules _______ 4 | ans: apply to the component where imported. 5 | Solution Description 6 | It is scoped by the web pack to the specific file where it is imported. 7 | 8 | 2. Styled components usage 9 | Send Feedback 10 | How to style an anchor tag using styled components 11 | ans: styled.a`color:white`. 12 | 13 | 3. Defining styled components 14 | Send Feedback 15 | Is it important to define styled components outside of the render method? 16 | ans: True. 17 | Solution Description 18 | It is important to define your styled components outside of the render method, otherwise it will be recreated on every single render pass. Defining a styled component within the render method will thwart caching and drastically slow down rendering speed, and should be avoided. 19 | 20 | 4. Props in styled components 21 | Send Feedback 22 | How to access props in a styled component? 23 | ans: styled.button`background: ${props=>props.color}` 24 | 25 | 5. Radium Media Queries 26 | Send Feedback 27 | The app needs to be wrapped inside which component while using media queries inside Radium? 28 | ans: StyleRoot. 29 | Solution Description 30 | StyleRoot wraps its children in a plain div followed by the root style sheet. Radium plugins, like keyframes and media queries, use this style sheet to inject CSS at runtime. Because the style sheet appears after your rendered elements, it is populated correctly during a server render. 31 | 32 | Further Readings: https://github.com/FormidableLabs/radium/tree/master/docs/api#styleroot-component 33 | 34 | 6. Scoped css 35 | Send Feedback 36 | What is the correct name for a scoped css file? 37 | ans: Scope.module.css. 38 | Solution Description 39 | When any file with the same name convention is imported in a file, the webpack scopes the classes by adding a unique string in its name. 40 | 41 | 7. Styled component 42 | Send Feedback 43 | Which is the correct name for a styled component? 44 | ans: BoxContainer. 45 | Solution Description 46 | The name should start with a capital letter. 47 | 48 | 8. True or False 49 | Send Feedback 50 | Is this declaration correct or wrong? 51 | const styledButton = styled.button` 52 | Background-color: ${(props) => { 53 | if(props.primary) return 'blue' 54 | else return 'red' 55 | }} 56 | `; 57 | ans: Wrong 58 | Solution Description 59 | We need to use `css` property to use multi line dynamic styling 60 | -------------------------------------------------------------------------------- /Questions and Exercises/12. Major Project Setup and Intro/Questions.txt: -------------------------------------------------------------------------------- 1 | 1. Which directory? 2 | Send Feedback 3 | In which directory, the small snippets you can use throughout the application are placed? 4 | ans: /utils. 5 | Solution Description 6 | It is a commonly used convention and the developer has a choice to use whatever folder structure is more meaningful in the project’s context. Some developers use “common”, “shared” or “utilities”. The most common practice is to have a util/utilities folder inside a common folder. 7 | 8 | 2. Which method? 9 | Send Feedback 10 | The ____________ method converts a JavaScript object or value to a JSON string and ____________ method is used to transform a JSON string into a Javascript object. 11 | ans: JSON.stringify(), JSON.parse(). 12 | Solution Description 13 | JSON.parse() takes a JSON string and transforms it into a JavaScript object. JSON.stringify() takes a JavaScript object and transforms it into a JSON string. 14 | 15 | 3. Correct Output 16 | Send Feedback 17 | What is the correct output of the given code. 18 | var x='6'; 19 | try { 20 | console.log("Before throw statement"); 21 | if(isNaN(x)) throw "is not a number"; 22 | x = Number(x); 23 | if(x > 5) throw "is too high"; 24 | console.log("After throw statement"); 25 | } 26 | catch(err) { 27 | console.log("Error caught : " + err); 28 | } 29 | finally { 30 | console.log("I am in finally!"); 31 | } 32 | ans: Before throw statement Error caught: is too high I am in finally!. 33 | Solution Description 34 | x is a string but it is a Number so, NaN will return false and then x is converted into a number. Since, it is greater than 5 it throws an error “is too high” and the next cole.log statement does not get executed. Error is caught and a message is displayed. Then control goes to the finally keyword and then "I am in finally!" gets printed. 35 | 36 | 4. Props Validation 37 | Send Feedback 38 | Which package is needed for Props validation? 39 | ans: Prop Types. 40 | Solution Description 41 | We are using props as arguments at every for passing things from parent component to child component. So, there is a need of validating props and this purpose is solved by prop type. Prop type basically checks that the prop that is being passed is validated or not. 42 | Documentation: https://www.npmjs.com/package/prop-types 43 | 44 | 5.HTTP Method 45 | Send Feedback 46 | Which of the following is not a HTTP method? 47 | ans: REMOVE 48 | Solution Description 49 | REMOVE is not a HTTP method. The primary or most-commonly-used HTTP methods are POST, GET, PUT, PATCH, and DELETE. These correspond to create, read, update, and delete (or CRUD) operations, respectively. 50 | 51 | 6. Authentication 52 | Send Feedback 53 | __________________ are created by an authentication service and contain information that enables a user to verify their identity without entering login credentials. 54 | ans: Authentication Tokens. 55 | Solution Description 56 | API keys are for projects, authentication is for users. 57 | API keys identify the calling project the application or site making the call to an API whereas Authentication tokens identify a user the person that is using the app or site. 58 | 59 | 7. The _________ method returns the value of the specified Storage Object item. 60 | ans: getItem(). 61 | Solution Description 62 | The getItem() method of the Storage interface, when passed a key name, will return that key's value, or null if the key does not exist, in the given Storage object. 63 | 64 | 8. What is a Callback? 65 | ans: Solution Description 66 | A callback is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of action. 67 | -------------------------------------------------------------------------------- /Questions and Exercises/13. React Hooks/Questions.txt: -------------------------------------------------------------------------------- 1 | 1. Using useEffect hook 2 | Which hook is analogous to react’s class lifecycle method componentDidMount? 3 | 4 | ans: useEffect(()=>{}, []). 5 | Solution Description 6 | The equivalent of componentDidMount in hooks is the useEffect function. Functions passed to useEffect are executed on every component rendering, unless you pass a second argument to it. 7 | 8 | 2. Whats wrong with code 9 | Send Feedback 10 | What’s wrong with the code 11 | 12 | 13 | Class Button { 14 | render () { 15 | const [text, setText] = useState(‘’); 16 | return 17 | } 18 | } 19 | ans: Cant use hooks inside a class. 20 | Solution Description 21 | Further Readings: 22 | https://reactjs.org/docs/hooks-faq.html#should-i-use-hooks-classes-or-a-mix-of-both 23 | 24 | 3. Can I .. 25 | Send Feedback 26 | Can we use the same hook multiple times in a function? 27 | 28 | ans: true. 29 | Solution Description 30 | The state of each component is completely independent. Hooks are a way to reuse stateful logic, not state itself. In fact, each call to a Hook has a completely isolated state. So, you can even use the same custom Hook twice in one component. 31 | 32 | 4. useState returns 33 | What does useState returns ? 34 | 35 | ans: A Pair. 36 | Solution Description 37 | useState hook returns the current state value and a function that lets you update it. 38 | 39 | 5. useState arguments 40 | How many arguments are passed to useState ? 41 | ans: 1. 42 | Solution Description 43 | Only argument is provided to useState which is its initial state. useState lets you use local state within a function component. You pass the initial state to this function and it returns a variable with the current state value (not necessarily the initial state) 44 | 45 | 6. useState Syntax 46 | Which of the following is the correct syntax for useState Hook ? 47 | ans: const[state, stateUpdaterFunction] = useState(initialStateValue). 48 | Solution Description 49 | Further Readings: 50 | https://reactjs.org/docs/hooks-state.html 51 | 52 | 7. Guess the count 53 | What will be the value of count after clicking the button? 54 | const UpdateState = () => { 55 | const [count, setCount] = useState(19) 56 | const handleClick = () => setCount(count + 2) 57 | return ( 58 |