<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>React Archives : Binary Bits</title>
	<atom:link href="https://blog.binarybits.net/category/web/react/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.binarybits.net/category/web/react/</link>
	<description>Bits &#38; Pieces - A blog by Kannan Balasubramanian</description>
	<lastBuildDate>Mon, 09 May 2022 07:45:52 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Binding buttons in SPFx</title>
		<link>https://blog.binarybits.net/binding-buttons-in-spfx/</link>
					<comments>https://blog.binarybits.net/binding-buttons-in-spfx/#respond</comments>
		
		<dc:creator><![CDATA[Kannan]]></dc:creator>
		<pubDate>Mon, 09 May 2022 07:44:06 +0000</pubDate>
				<category><![CDATA[React]]></category>
		<category><![CDATA[SharePoint]]></category>
		<guid isPermaLink="false">https://blog.binarybits.net/?p=1570</guid>

					<description><![CDATA[<p>When writing a react based SPFx application one has to make a note that ES6 React.Component doesn&#8217;t auto bind methods to itself. Hence it&#8217;s required to manually bind and the following are two ways to do it. Method 1 onClick={this.addButtonClicked.bind(this)} Method 2 this.addButtonClicked = this.addButtonClicked.bind(this);</p>
<p>The post <a href="https://blog.binarybits.net/binding-buttons-in-spfx/">Binding buttons in SPFx</a> appeared first on <a href="https://blog.binarybits.net">Binary Bits</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>When writing a react based SPFx application one has to make a note that ES6 React.Component doesn&#8217;t auto bind methods to itself.</p>



<p>Hence it&#8217;s required to manually bind and the following are two ways to do it.</p>



<h2 class="wp-block-heading">Method 1</h2>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>onClick={this.addButtonClicked.bind(this)}</p></blockquote>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;application/typescript&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;TypeScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;typescript&quot;}">import * as React from 'react';

import { Stack, IStackProps, IStackStyles } from 'office-ui-fabric-react/lib/Stack';
import { ActionButton } from 'office-ui-fabric-react/lib/Button';
import { IIconProps } from 'office-ui-fabric-react/';

import { ITestComponentState } from './ITestComponentState';
import { ITestComponentProps } from './ITestComponentProps';

//Stack related styles
const outerStackTokens = {
    childrenGap: 50
};
const addFriendIcon: IIconProps = { iconName: 'Add' };

let outerStackStyles: Partial&lt;IStackStyles&gt; = {};
let innerStackColumnProps: Partial&lt;IStackProps&gt; = {};

export default class TestComponent extends React.Component&lt;ITestComponentProps, ITestComponentState&gt; {
    constructor(props: ITestComponentProps) {
        super(props);
        this.state = {
            items: []
        };
    }
  
    public render(): React.ReactElement&lt;{}&gt; {
        return (
            &lt;div&gt;
                &lt;Stack horizontal tokens={outerStackTokens} styles={outerStackStyles}&gt;
                    &lt;Stack verticalAlign=&quot;start&quot; {...innerStackColumnProps}&gt;
                        &lt;Stack.Item align=&quot;start&quot; &gt;
                            &lt;ActionButton iconProps={addFriendIcon} onClick={this.addButtonClicked.bind(this)} allowDisabledFocus disabled={this.state.sortItems.length &gt;= 10 ? true : false} &gt;Add Item&lt;/ActionButton&gt;
                        &lt;/Stack.Item&gt;
                    &lt;/Stack&gt;
                &lt;/Stack&gt;
            &lt;/div&gt;
        );
    }

    private addButtonClicked(event?: React.MouseEvent&lt;HTMLButtonElement&gt;) {
        let itemsOnAdd = this.state.items;
        let itemTitle = &quot;Item &quot; + (this.state.items.length + 1);
        itemsOnAdd.push({ title: itemTitle });
        this.setState({ items: itemsOnAdd });
    }
}</pre></div>



<h2 class="wp-block-heading">Method 2</h2>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>this.addButtonClicked = this.addButtonClicked.bind(this);</p></blockquote>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;application/typescript&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;TypeScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;typescript&quot;}">import * as React from 'react';

import { Stack, IStackProps, IStackStyles } from 'office-ui-fabric-react/lib/Stack';
import { ActionButton } from 'office-ui-fabric-react/lib/Button';
import { IIconProps } from 'office-ui-fabric-react/';

import { ITestComponentState } from './ITestComponentState';
import { ITestComponentProps } from './ITestComponentProps';

//Stack related styles
const outerStackTokens = {
    childrenGap: 50
};
const addFriendIcon: IIconProps = { iconName: 'Add' };

let outerStackStyles: Partial&lt;IStackStyles&gt; = {};
let innerStackColumnProps: Partial&lt;IStackProps&gt; = {};

export default class TestComponent extends React.Component&lt;ITestComponentProps, ITestComponentState&gt; {
    constructor(props: ITestComponentProps) {
        super(props);
        this.state = {
            items: []
        };
        this.addButtonClicked = this.addButtonClicked.bind(this);
    }
  
    public render(): React.ReactElement&lt;{}&gt; {
        return (
            &lt;div&gt;
                &lt;Stack horizontal tokens={outerStackTokens} styles={outerStackStyles}&gt;
                    &lt;Stack verticalAlign=&quot;start&quot; {...innerStackColumnProps}&gt;
                        &lt;Stack.Item align=&quot;start&quot; &gt;
                            &lt;ActionButton iconProps={addFriendIcon} onClick={this.addButtonClicked} allowDisabledFocus disabled={this.state.sortItems.length &gt;= 10 ? true : false} &gt;Add Item&lt;/ActionButton&gt;
                        &lt;/Stack.Item&gt;
                    &lt;/Stack&gt;
                &lt;/Stack&gt;
            &lt;/div&gt;
        );
    }

    private addButtonClicked(event?: React.MouseEvent&lt;HTMLButtonElement&gt;) {
        let itemsOnAdd = this.state.items;
        let itemTitle = &quot;Item &quot; + (this.state.items.length + 1);
        itemsOnAdd.push({ title: itemTitle });
        this.setState({ items: itemsOnAdd });
    }
}</pre></div>
<p>The post <a href="https://blog.binarybits.net/binding-buttons-in-spfx/">Binding buttons in SPFx</a> appeared first on <a href="https://blog.binarybits.net">Binary Bits</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.binarybits.net/binding-buttons-in-spfx/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>React &#8211; Call function from HTML Tag with parameter</title>
		<link>https://blog.binarybits.net/call-react-function-from-html-with-parameter/</link>
					<comments>https://blog.binarybits.net/call-react-function-from-html-with-parameter/#respond</comments>
		
		<dc:creator><![CDATA[Kannan]]></dc:creator>
		<pubDate>Sun, 26 Apr 2020 08:26:06 +0000</pubDate>
				<category><![CDATA[React]]></category>
		<guid isPermaLink="false">https://blog.binarybits.net/?p=1236</guid>

					<description><![CDATA[<p>Sometimes we need to call a React function from HTML tags with parameters or arguments and following is the ES6 based way. Here a button is calling a function updateName with argument newName to set a state which in turns changes the name being displayed. Do note that using this.updateName.bind() is the recommended way due [&#8230;]</p>
<p>The post <a href="https://blog.binarybits.net/call-react-function-from-html-with-parameter/">React &#8211; Call function from HTML Tag with parameter</a> appeared first on <a href="https://blog.binarybits.net">Binary Bits</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p><img decoding="async" class="wp-image-1249" style="width: 64px;" src="https://blog.binarybits.net/wp-content/uploads/2020/04/react-logo.svg" alt="React">Sometimes we need to call a React function from HTML tags with parameters or arguments and following is the ES6 based way.</p>



<p>Here a button is calling a function <em>updateName</em> with argument <em>newName</em> to set a state which in turns changes the name being displayed. </p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text/javascript&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}">import React, { Component } from 'react';
import { render } from 'react-dom';
import './style.css';

class App extends Component {
  constructor() {
    super();
    this.state = {
      name: 'Kannan'
    };
  }

  updateName = (newName) =&gt;{
    this.setState({
      name: newName
    })
  }

  render() {
    return (
      &lt;div&gt;
        &lt;p&gt;My Name is {this.state.name}.&lt;/p&gt;
        &lt;p&gt;          
          &lt;button onClick={this.updateName.bind(this,'Kannan Balasubramanian')}&gt;Change the name&lt;/button&gt;&lt;br/&gt;
          &lt;button onClick={()=&gt;this.updateName('Kannan Balasubramanian!')}&gt;Change the name again&lt;/button&gt;
        &lt;/p&gt;
      &lt;/div&gt;
    );
  }
}

render(&lt;App /&gt;, document.getElementById('root'));</pre></div>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Do note that using <em>this.updateName.bind()</em> is the recommended way due to performance and efficiency concerns.</p></blockquote>



<p>You can try the sample output <a rel="noreferrer noopener" href="https://kannan-public-react-call-function-from-html-tag.stackblitz.io" target="_blank">here</a>.</p>
<p>The post <a href="https://blog.binarybits.net/call-react-function-from-html-with-parameter/">React &#8211; Call function from HTML Tag with parameter</a> appeared first on <a href="https://blog.binarybits.net">Binary Bits</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.binarybits.net/call-react-function-from-html-with-parameter/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: blog.binarybits.net @ 2026-05-14 12:13:13 by W3 Total Cache
-->