3
3
* - components are classes in react js
4
4
* - All components should start with a capital letter
5
5
* - Components are functions
6
- *
6
+ *
7
7
* Life Cycle State and Methods
8
- * - We have 3 states: Mount, Update, Unmount
8
+ * - We have 3 states: Mount, Update, Unmount
9
9
* - Each state has their own methods
10
10
* - Mount State
11
11
* - componentWillMount Method
12
12
* - is invoked once both on the client and on the server
13
- * - immediately before the inital render occurs, if you call setState() within this method, render will
13
+ * - immediately before the inital render occurs, if you call setState() within this method, render will
14
14
* see this updated state and will be excuted only once despite the state change
15
15
* - componentDidMount Method
16
16
* - is invoked once only on the client, not on the server
17
17
* - immediately after the inital render occurs, at this point in the life cycle the component has DOM
18
18
* representation which you can access via React.findDOMNode(component)
19
19
* - if you want to integrate with other js frameworks, set timers using setTimeout() or setInterval() or
20
- * send ajax requests, you can perform those operations in this method. Soon as component is mounted, we can do
20
+ * send ajax requests, you can perform those operations in this method. Soon as component is mounted, we can do
21
21
* our stuff inside that method.
22
22
* - Update State
23
23
* - componentWillReceiveProps Method
24
- * - is invoked when a component is receiving new properties.
24
+ * - is invoked when a component is receiving new properties.
25
25
* - this method is not called for the inital render. We can use this as an opportunity to react to a property
26
26
* transition before render is called by updating the state using this.setState(). The old properties can be
27
27
* accessed via this.props calling this.setState() within this function will not a trigger an additional render
28
28
* - shouldComponentUpdate Method
29
29
* - is invoked before rendering when new properties or state are being received. This method is not called for the
30
- * inital render or than a forced update is used. We can use this as an opportunity to reinforce when you are certain
30
+ * inital render or than a forced update is used. We can use this as an opportunity to reinforce when you are certain
31
31
* that the transition to the new props and state will not require a component update. Should the component update
32
- * returns false, than render will be completely skipped, handling the next state change. In addition
32
+ * returns false, than render will be completely skipped, handling the next state change. In addition
33
33
* componentWillUpdate and componentDidUpdate will not be called as well. By default shouldComponentUpdate always
34
34
* return true to prevent settled bugs and state is mutated in place, but if your careful to always treat state as
35
35
* immutable and to read only from properties and state in render. Than you can over ride shouldComponentUpdate with
36
36
* a implentation that compares the old properties and state to their replacements
37
37
* - componentWillUpdate Method
38
- * - is invoked immediately before rendering. When new properties or state are being recieved. This method is not
38
+ * - is invoked immediately before rendering. When new properties or state are being recieved. This method is not
39
39
* called for the inital render
40
40
* - componentDidUpdate Method
41
41
* - is invoked immediately after the components updates are flushed to the DOM
42
- * - This method is not called for the inital render
43
- * - We can use this method to operate on the DOM when the component
42
+ * - This method is not called for the inital render
43
+ * - We can use this method to operate on the DOM when the component
44
44
* has been updated
45
45
* - Unmount State
46
46
* - componentWillUnmount Method
47
47
* - is invoked immediately before a component is unmonted from the DOM. We can perform any necessary clean up in this
48
- * method or you can say garbage collection. Such as invalidating timers or clearing up any DOM elements that were
48
+ * method or you can say garbage collection. Such as invalidating timers or clearing up any DOM elements that were
49
49
* created in componentDidMount
50
- *
50
+ *
51
51
* COMPONENT STATE Methods
52
52
* - render
53
53
* - only returns one element
54
- * - if you do not want to return nothing at all you can simply write null or false to indicate you don't want
54
+ * - if you do not want to return nothing at all you can simply write null or false to indicate you don't want
55
55
* anything rendered behind the scenes
56
- * - the render function should not modify component state. It should always return the same results each time
57
- * its invoked and does not read or write to DOM. In case you need to interact with the browser, you need to
56
+ * - the render function should not modify component state. It should always return the same results each time
57
+ * its invoked and does not read or write to DOM. In case you need to interact with the browser, you need to
58
58
* perform your work and methods like componentDidMount or other life cycle methods instead
59
59
* - keeping render pure this way makes server rendering more practical and components easier to think
60
60
* - getInitialState
61
- * - when ever this is invoked, once before the component is mounted, the return value will used
61
+ * - when ever this is invoked, once before the component is mounted, the return value will used
62
62
* as the inital value of "this.state" property
63
63
* - getDefaultProps
64
- * - this invoked once and cached when the class is created. This method is invoked before any instances
64
+ * - this invoked once and cached when the class is created. This method is invoked before any instances
65
65
* are created and thus cannot rely on "this.props"
66
66
* - in addition be aware that any complex objects return by getDefaultProps will be shared across instances and
67
67
* not copied
70
70
* - mixins
71
71
* - a mixin is a group of methods that sits on one object that gets copied over to another object
72
72
* - a fantastic method react provides us to easily reuse code
73
- * - mixins array allows you to use mixins to share behavior amoung multiple components. This will also be apart
73
+ * - mixins array allows you to use mixins to share behavior amoung multiple components. This will also be apart
74
74
* of reusable components.
75
75
* - statics
76
76
* - statics object allows you to define static methods that can be called on the component class
77
77
* - displayName
78
78
* - displayName is a string used in debugging msgs and usually jsx sets this value automatically
79
- */
79
+ */
0 commit comments