React Flashcards

1
Q

React component must act like pure function with respect to their props

A

React component must act like pure function with respect to their props

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Js react callback binding

A
If you refer to a method without () after it, you should bind that method. 
In constructor: this.handleClick = this.handleClick.bind(this);
Or: use class field syntax. Check React Doc main concepts, 6
onClick ={{ () => this.handleClick()}}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

空格还是逗号

A

tag里面,各等式之间空格,object里,各:pair之间用逗号

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

&&

A

true ‘&&’ expression evaluates to expression

false && expression evaluates to false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

? :

A

condition? true: false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Key

A

Kay is a special string attribute you need to include when creating lists of elements

<li>{...}</li>

Most often, you should use id for key
Not recommended to use index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Key more

A

Key应该用在构建一组list中,而不是单个li组件。通常在map()call中

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Object.keys()

A

???

return array with keys

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Form, controlled components

A

用setState来控制form的value,开始,this.state规定了value,如果没有包在onChange中的setState来改变value的话,用户是无法输入或更改信息的。而onChange保证了信息的实时更新,不仅仅是UI中的变化,也包括实时的this.state.value
handleChange(event) {
this.setState({value: event.target.value});
}

onChange={this.handleChange}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

controlled components, onSubmit preventDefault()

A

html 自带的,submit以后要refresh浏览器,更新state并把数据传送到后端,React controlled components 自动完成这些,不再需要refresh,而且会造成错误,所以在submit的function里要加入event.preventDefault()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

parseInt; parseFloat(string)

A

User输入的都是string,用这些转换

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Object后面用. 还是[]

A

[‘key’]

.key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

props and state

A

props read only;

state could be modified

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Controlled components for multiple inputs

A

Check class material or react doc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

map()经验

A

map =>后面如果是跟html element,一定不能加{}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

class 里面新的method里的变量 经验教训

A

前面一定要加var或者const