โ๏ธ If the post is submited but the user cannot call the post, that's cuz the user tried to call the post before the post got fully submitted.
โก๏ธ So the user must call the post whenever the posting is fully done. And the process that the user is calling the post before the final submission is called Asyncronous.
The opposite thing for asyncronous is syncronous, which the user can call the post whenever the post is fully submitted.
Examples)
โฟ Asyncronous:
โฐ Syncronous:
const data = axios.get('http://koreanjson.com/posts/1')
console.log(data)
//promise
โก๏ธ This command changes asynchronous code to synchronous code.
--> Basically changing async to waiting status.
--> await ALLWAYS follows behind async.
console.log(aaa)
var aaa = 3
console.log(bbb)
const bbb = 2
๐จ index.js โฌ๏ธ
import axios from 'axios'
import {useState} from 'react'
import {useMutation, gql} from '@apollo/client'
import { defaultFieldResolver } from 'graphql'
const CREATE_PRODUCT = gql`
mutation createProduct($seller: String!, $createProductInput: CreateProductInput!){
createProduct(seller: $seller, createProductInput: $createProductInput){
_id
number
message
}
}
`
export default function GraphqlMutationProduct(){
const [mySeller, setMySeller] = useState("")
const [myName , setMyName] = useState("")
const [myContents, setMyContents] = useState("")
const [myPrice, setMyPrice] = useState("")
const [createProduct] = useMutation(CREATE_PRODUCT)
const OnclickSubmit = async() => {
await createProduct({
variables: {
seller: "JB",
createProductInput: {
name: "Phone",
detail: "Great",
price: Number(myPrice)
}
}
})
}
const onChangeMySeller = (event) => {
setMySeller(event.target.value)
}
const onChangeMyName = (event) => {
setMyName(event.target.value)
}
const onChangeMyContents = (event) => {
setMyContents(event.target.value)
}
const onChangeMyPrice = (event) => {
setMyPrice(event.target.value)
}
return(
<>
Seller: <input type= "text" onChange={onChangeMySeller} /><br/>
Product: <input type= "text" onChange={onChangeMyName}/><br/>
Info: <input type= "text" onChange={onChangeMyContents}/><br/>
Price: <input type= "text" onChange={onChangeMyPrice}/><br/>
<button onClick={OnclickSubmit}>Post the Product</button>
</>
)
}
๐ช Playground โฌ๏ธ
โ๏ธ Seller gets itโs value through $seller, which is getting its userInput value of string.
--> Same for createProductInput.
โ๏ธ < const [execution function] = useMutation(CREATE_PRODUCT) >
--> Function variable should be typed inside ().
--> If the user is creating a profile, createProfile should be typed in.
โ๏ธ Break: Breaks the loop when the command is given.
๐ continue: Stops the loop when the condition matches then continues after the condition.
Types
*For (let key in object){}
*For (let key of object){}
*Array.forEach(function())
๐ก โฌ๏ธ Example of for(in) โฌ๏ธ
const obj = {
name: "JB",
age: 12,
school: "CodeCamp"
}
for (let key in obj) {
console.log(key, obj[key])
}
//result: 'name' 'JB'
'age' 12
'school' 'CodeCamp'
โ๏ธ Age printed as number.
โ๏ธ As a result, the key and values are separately printed.
const str = "abcde"
for (let key in str){
console.log(key)
}
//result: '0'
'1'
'2'
'3'
'4'
โ๏ธ This prints the index of string.
๐ต โฌ๏ธ Example of for(of) โฌ๏ธ
const str = "what"
for (let key of str){
console.log(key)
}
//result: 'w'
'h'
'a'
't'
โ๏ธ This prints elements of string.
๐ฃ โฌ๏ธ Example of forEach โฌ๏ธ
const arr = ["Hi","Good Morning", "Bye", "Good Night"];
arr.forEach(( data ) => {
console.log(data)
})
//result: 'Hi'
'Good Morning'
'Bye'
'Good Night'
โ๏ธ This prints elements of array.
const arr = ["a","b","c"];
arr.forEach (( data, index) => {
console.log(data, index)
})
//result: 'a' 0
'b' 1
'c' 2
```js
โ๏ธ This prints the **data** inside the array and it's **index** number.
**๐ค โฌ๏ธ Example of While loop โฌ๏ธ**
```js
let current =1; //๋ก๋ด ํ์ฌ ์์น
let answer =0; //์ด๋ํ์
while (current !== 100){
current++;
answer ++;
}
//result: 98
โ๏ธ When the statement is true, the statement is operated.
โ๏ธ current: Robot's current location
โ๏ธ answer: Number of stairs the robot moved