defaultValue
--> Show the previous input that the user wrote inside the input box.
readOnly()
--> If the user tries to edit this on browser, it is unable to edit. It's not even able to click the input box.
props.data?.fetchBoard.title
--> props.isEdit ? true : false
Method 1 (Not really recommended)
Method 2 (Efficient way to do)
Re-factoring
Literally factoring again to make the code more efficient.
Return
Ending/quiting the statement if the condition matches. After return is stated and used, rest of the codes can not be reached.
Pattern
Developers making their own rules to make the team project or even personal programmings clearly.
Shortcut
command + optinon + โก๏ธ
argument
*If the user write the code written below in container-
const add = (a:number, b:number)=> {
return a+b
}
and sets add as {add} to ues props method-
add={add}
-then goes to presenter. The user writes props.add(1,2) to tell the computer what data the user is getting.
--> Receiver should know what data they are receiving.
ex) ChangeEvent: tells how the userInput changed through inserting the contents inside the bracket.
ex) MouseEvent: event happening once the button is clicked.
API response data: Graphql-codegen
Install
1. Google "graphql codegen"
2. Go to docs
3. copy yarn add -D @graphql-codegen/cli
4. Go to class folder and make new file --> codegen.yml
5. Paste codegen.yml
schema: schema.graphql # you can also point to a GraphQL endpoint!
generates:
types.ts:
plugins:
- @graphql-codegen/typescript
{
"scripts": {
"generate": "graphql-codegen"
}
}
๐ Eslint: code linter
ex sequence for imports
ex No using ==
ex Allow using ===
--> Eslint is basically like a rule for group projects.
๐ prettier: code formatter
ex 2 indents
ex If the length exceeds 00 amount, go to next line
--> Prettier basically makes the code look pretty and clear.
const arr = [1,2,41,102,5]
arr.sort()
result: [1,102,2,4,5]
โฌ๏ธ Correct way for Acsending form of sort()
arr = [1,3,9,12,102,86]
arr.sort((a,b)=> {
return a - b //but only able for numbers not string form
})
arr
โฌ๏ธ Descending form of sort()
arr = [1,3,9,12,102,86]
arr.sort((a,b)=> {
return b - a
})
arr
โฌ๏ธ How it works
jsarr = ['a','b','Z','A','f','z']
'a' < 'b'
'z' >'f'
'z' > 'w'
'f' > 'w'
โฌ๏ธ DAY 10 Practice
function solution(s) {
const answer = [];
for (let i=0;i<s.length; i++){
answer.push(s[i])
}
answer.sort((a,b) => {
return a > b ? -1 : 1
})
let result =""
for (let i= 0; i<answer.length; i++){
result +=answer[i]
}
return result;
}