Search This Blog

Monday, May 25, 2020

Drop down selection change event in React Js in SPFX webpart

import * as React from 'react'; 
import styles from './Reactspfx.module.scss'; 
import { IReactspfxProps } from './IReactspfxProps'; 
import { escape } from '@microsoft/sp-lodash-subset'; 
export interface IReactGetItemsState
{ selectValue:string }
 export default class Reactspfx extends React.Component { 
public constructor(props: IReactspfxProps) {
 super(props); 
this.state = { 
selectValue:"Radish"
 };
}
handleChange = (event) => { this.setState({selectValue:event.target.value}); alert(event.target.value); };
public render(): React.ReactElement { alert(this.state.selectValue); return (
  <select value={this.state.selectValue}  onChange={this.handleChange}>
    <option value="Orange">Orange</option>
      <option value="Radish">Radish</option>
      <option value="Cherry">Cherry</option>
    </select>
);
}

No comments:

Post a Comment