generate ssh key
for windows user
go to gitbash and use command
ssh-keygen -t rsa -b 4096 -C "youremail@example.com"
generate ssh key
for windows user
go to gitbash and use command
ssh-keygen -t rsa -b 4096 -C "youremail@example.com"
Middleware are functions that can be used for handling request and response objects.
In practice, you can use several middlewares at the same time. When you have more than one, they're executed one by one in the order that they were taken into use in the express.
In practice, you can use several middleware at the same time. When you have more than one, they're executed one by one in the order that they were taken into use in express.
Middleware is a function that receives three parameters:
const requestLogger = (request, response, next) => {
console.log('Method:', request.method)
console.log('Path: ', request.path)
console.log('Body: ', request.body)
console.log('---')
next()
}//cheatsheet
/* key words */
collection = table
/* for databses */
view all databases
-show dbs
create a new or switch databases
-use <databse_name>
view current database
-db
delete database
-db.dropDatabase()
/* for collections */
Show Collections
-show collections
create a collection name 'comments'
-db.createCollection('comments')
delete collections
-db.<collection_name>.drop()
/* mongodb command for rows*/
Show All Rows In a Collection
-db.<collection_name>.find()
-db.<collection_name>.find().pretty() //for preetyfied view
-db.<collection_name>.findOne() // for finding 1st row
Insert One Rows
-db.<collection_name>.insert({'name':'Gyanendra','lang':'javaScript','age':'24'})
Insert Many Rows
-db.<collection_name>.insertMany([{'name':'Gyanendra','lang':'javaScript','age':'24'},{'name':'Gyanendra','lang':'javaScript','age':'24'},{'name':'Arvind','lang':'javaScript','age':'24'},])
Search In a Mongodb Database
-db.<collection_name>.find({'name':'Arvind'})
Limit The Number of Rows In Output
-db.<collection_name>.find().limit(10)
Count Rows
-db.<collection_name>.count()
or
-db.<collection_namee>.limit(3).count()
//these two has same output because limit only limits the output data not the whole data
Today I’ll be going over how data is passed between parent and child components in React. There are two directions a data can go and it’s the following:
I’ll be going over these in the following sections.
When you need to pass data from a parent to child class component, you do this by using props.
For example, let’s say you have two class components, Parent and Child, and you want to pass a state in the parent to the child. You would do something like this:
| import React from 'react'; | |
| class Parent extends React.Component{ | |
| constructor(props){ | |
| super(props); | |
| this.state = { | |
| data: 'Data from parent' | |
| } | |
| } | |
| render(){ | |
| const {data} = this.state; | |
| return( | |
| <div> | |
| <Child dataParentToChild = {data}/> | |
| </div> | |
| ) | |
| } | |
| } | |
| class Child extends React.Component{ | |
| constructor(props){ | |
| super(props); | |
| this.state = { | |
| data: this.props.dataParentToChild | |
| } | |
| } | |
| render(){ | |
| const {data} = this.state; | |
| return( | |
| <div> | |
| {data} | |
| </div> | |
| ) | |
| } | |
| } | |
| export default Parent; |
As you can see, the parent component passes props to the child component and the child can then access the data from the parent via this.props.
For the same example, if you have two function components instead of class components, you don’t even need to use props. You can do something like the following:
| import React from 'react'; | |
| function Parent(){ | |
| const data = 'Data from parent'; | |
| return( | |
| <div> | |
| <Child dataParentToChild = {data}/> | |
| </div> | |
| ) | |
| } | |
| function Child ({dataParentToChild}){ | |
| return( | |
| <div> | |
| {dataParentToChild} | |
| </div> | |
| ) | |
| } | |
| export default Parent; |
Passing the data from the child to parent component is a bit trickier. In order to do this, you need to do the following steps:
Let’s see how these steps are implemented using an example. You have two class components, Parent and Child. The Child component has a form that can be submitted in order to send its data up to the Parent component. It would look something like this:
| import React from 'react'; | |
| class Parent extends React.Component{ | |
| constructor(props){ | |
| super(props); | |
| this.state = { | |
| data: null | |
| } | |
| } | |
| handleCallback = (childData) =>{ | |
| this.setState({data: childData}) | |
| } | |
| render(){ | |
| const {data} = this.state; | |
| return( | |
| <div> | |
| <Child parentCallback = {this.handleCallback}/> | |
| {data} | |
| </div> | |
| ) | |
| } | |
| } | |
| class Child extends React.Component{ | |
| onTrigger = (event) => { | |
| this.props.parentCallback("Data from child"); | |
| event.preventDefault(); | |
| } | |
| render(){ | |
| return( | |
| <div> | |
| <form onSubmit = {this.onTrigger}> | |
| <input type = "submit" value = "Submit"/> | |
| </form> | |
| </div> | |
| ) | |
| } | |
| } | |
| export default Parent; |
As you can see, when the Child component is triggered, it will call the Parent component’s callback function with data it wants to pass to the parent. The Parent’s callback function will handle the data it received from the child.
We’ve gone over passing data between a parent and child components in React. Just as a recap, here’s the different methods we’ve covered:
Dapper is a micro ORM library for .NET and .NET Core applications that allows you to execute SQL queries and map the results to objects. D...