Monday 25 May 2020

Dropdown Selection Change Event in React Js

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>
);
}

SHAREPOINT FRAMEWORK - REACT JS alert on Page Load

Here is my code for getting alert on page load.
componentDidMount() {   
  alert("Hi");
}

public render(): React.ReactElement<IReactCrudProps> {   
    return ( 
        <select id="myDDl">

        </select>
    );
}