You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
React lets you add <em>event handlers</em> to your JSX. Event handlers are your own functions that will be triggered in response to interactions like clicking, hovering, focusing form inputs, and so on.
2222
+
React lets you add <em>event handlers</em> to your PSX. Event handlers are your own functions that will be triggered in response to interactions like clicking, hovering, focusing form inputs, and so on.
<p>To add an event handler, you will first define a function and then <ahref="/learn/passing-props-to-a-component">pass it as a prop</a> to the appropriate JSX tag. For example, here is a button that doesn't do anything yet:</p>
2234
+
<p>To add an event handler, you will first define a function and then <ahref="../passing-props-to-a-component/">pass it as a prop</a> to the appropriate PSX tag. For example, here is a button that doesn't do anything yet:</p>
<spanclass="k">return</span><spanclass="n">html</span><spanclass="o">.</span><spanclass="n">button</span><spanclass="p">(</span><spanclass="s2">"I don't do anything"</span><spanclass="p">)</span>
<p>You can make it show a message when a user clicks by following these three steps:</p>
2242
2252
<ol>
2243
-
<li>Declare a function called <code>handleClick</code><em>inside</em> your <code>Button</code> component.</li>
2244
-
<li>Implement the logic inside that function (use <code>alert</code> to show the message).</li>
2245
-
<li>Add <code>on_click={handleClick}</code> to the <code><button></code>JSX.</li>
2253
+
<li>Declare a function called <code>handle_click</code><em>inside</em> your <codeclass="highlight"><spanclass="k">def</span><spanclass="nf">button</span><spanclass="p">():</span></code> component.</li>
2254
+
<li>Implement the logic inside that function (use <code>print</code> to show the message).</li>
2255
+
<li>Add <code>on_click=handle_click</code> to the <code>html.button</code>PSX.</li>
<p>You defined the <code>handleClick</code> function and then <ahref="/learn/passing-props-to-a-component">passed it as a prop</a> to <code><button></code>. <code>handleClick</code> is an <strong>event handler.</strong> Event handler functions:</p>
2268
2294
<ul>
2269
2295
<li>Are usually defined <em>inside</em> your components.</li>
0 commit comments