@@ -32,7 +32,7 @@ use_state
3232 Returns a stateful value and a function to update it.
3333
3434During the first render the ``state `` will be identical to the ``initial_state `` passed
35- as the first argument. However in subsiquent renders ``state `` will take on the value
35+ as the first argument. However in subsequent renders ``state `` will take on the value
3636passed to ``set_state ``.
3737
3838.. code-block ::
@@ -41,7 +41,7 @@ passed to ``set_state``.
4141
4242 The ``set_state `` function accepts a ``new_state `` as its only argument and schedules a
4343re-render of the element where ``use_state `` was initially called. During these
44- subsiquent re-renders the ``state `` returned by ``use_state `` will take on the value
44+ subsequent re-renders the ``state `` returned by ``use_state `` will take on the value
4545of ``new_state ``.
4646
4747.. note ::
@@ -56,7 +56,7 @@ Functional Updates
5656
5757If the new state is computed from the previous state, you can pass a function which
5858accepts a single argument (the previous state) and returns the next state. Consider this
59- simple use case of a counter where we've pulled out logic for incrementing and
59+ simply use case of a counter where we've pulled out logic for incrementing and
6060decrementing the count:
6161
6262.. literalinclude :: examples/use_state_counter.py
@@ -65,7 +65,7 @@ decrementing the count:
6565
6666We use the functional form for the "+" and "-" buttons since the next ``count `` depends
6767on the previous value, while for the "Reset" button we simple assign the
68- ``initial_count `` since it's independent of the prior ``count ``. This is a trivial
68+ ``initial_count `` since it is independent of the prior ``count ``. This is a trivial
6969example, but it demonstrates how complex state logic can be factored out into well
7070defined and potentially reuseable functions.
7171
@@ -103,19 +103,17 @@ use_effect
103103
104104 use_effect(did_render)
105105
106- The ``use_effect `` hook accepts a function which is may be imperative, or mutate state.
107- The function will be called once the element has rendered, that is, when the
108- element's render function and those of any child elements it produces have rendered
109- successfully.
106+ The ``use_effect `` hook accepts a function which may be imperative, or mutate state. The
107+ function will be called immediately after the layout has fully updated.
110108
111- Mutations, subscriptsion , delayed actions, and other `side effects `_ can cause
109+ Mutations, subscriptions , delayed actions, and other `side effects `_ can cause
112110unexpected bugs if placed in the main body of an element's render function. Thus the
113111``use_effect `` hook provides a way to safely escape the purely functional world of
114112element render functions.
115113
116114.. note ::
117115
118- Normally in react the ``did_render `` function is called once an update has been
116+ Normally in React the ``did_render `` function is called once an update has been
119117 commited to the screen. Since no such action is performed by IDOM, and the time
120118 at which the update is displayed cannot be known we are unable to achieve parity
121119 with this behavior.
@@ -124,15 +122,16 @@ element render functions.
124122Cleaning Up Effects
125123...................
126124
127- If the effect you wish to enact creates resources you'll probably need to clean them up.
128- In such cases you may simply return a function the addresses this from the function
129- which created the resource. Consider the case of opening and then closing a connection:
125+ If the effect you wish to enact creates resources, you'll probably need to clean them
126+ up. In such cases you may simply return a function that addresses this from the
127+ ``did_render `` function which created the resource. Consider the case of opening and
128+ then closing a connection:
130129
131130.. code-block ::
132131
133132 def establish_connection():
134133 connection = open_connection(url)
135- return connection.close
134+ return lambda: close_connection( connection)
136135
137136 use_effect(establish_connection)
138137
@@ -145,7 +144,7 @@ time an element renders.
145144Conditional Effects
146145...................
147146
148- By default effects are triggered after ever successful render to ensure that all state
147+ By default, effects are triggered after every successful render to ensure that all state
149148referenced by the effect is up to date. However you can limit the number of times an
150149effect is fired by specifying exactly what state the effect depends on. In doing so
151150the effect will only occur when the given state changes:
@@ -154,7 +153,7 @@ the effect will only occur when the given state changes:
154153
155154 def establish_connection():
156155 connection = open_connection(url)
157- return connection.close
156+ return lambda: close_connection( connection)
158157
159158 use_effect(establish_connection, [url])
160159
@@ -210,12 +209,12 @@ use_callback
210209
211210 A derivative of :ref: `use_memo `, the ``use_callback `` hook teturns a
212211`memoized <memoization >`_ callback. This is useful when passing callbacks to child
213- elements which check reference equality to prevent unnecessary renders. The of the
212+ elements which check reference equality to prevent unnecessary renders. The of
214213``memoized_callback `` will only change when the given depdencies do.
215214
216215.. note ::
217216
218- The list of "dependencies" are not passed as arguments to the function ostensibly
217+ The list of "dependencies" are not passed as arguments to the function. Ostensibly
219218 though, that is what they represent. Thus any variable referenced by the function
220219 must be listed as dependencies. We're working on a linter to help enforce this
221220 [GH202 ]_.
@@ -243,9 +242,9 @@ after) and should not incur side effects.
243242
244243.. warning ::
245244
246- Remember that you shouldn't optimize something else you know it's a performance
247- bottleneck. Write your code without ``use_memo `` first and then add it to later
248- to targeted sections that need a speed-up.
245+ Remember that you shouldn't optimize something unless you know it's a performance
246+ bottleneck. Write your code without ``use_memo `` first and then add it to targeted
247+ sections that need a speed-up.
249248
250249.. note ::
251250
@@ -267,9 +266,9 @@ Returns a mutable :class:`~idom.core.hooks.Ref` object that has a single
267266``initial_state ``. The identity of the ``Ref `` object will be preserved for the lifetime
268267of the element.
269268
270- A ``Ref `` is most useful if you need to incur side effect since updating its
269+ A ``Ref `` is most useful if you need to incur side effects since updating its
271270``.current `` attribute doesn't trigger a re-render of the element. You'll often use this
272- hook alongside :ref: `use_effect ` or in response to element event handlers. The
271+ hook alongside :ref: `use_effect ` or in response to element event handlers.
273272:ref: `The Game Snake ` provides a good use case for ``use_ref ``.
274273
275274
0 commit comments