Fetching data from Sharepoint List and Displaying it.
1-- import { Sp } from "./Environment/Env";
2-- Add Environment file into components.
3-- Write ComponentDidMount to fetch the data from the sharepoint list eg:
public async componentDidMount() {
await Sp.lists.getByTitle("Name of your List").items.select("Title",
"User_Name", "Business_Unit", "Manager", "Organization_Info",
"BU_Head").get().then((res: any) => {
this.setState({ Title: res[0].Title });
this.setState({ Manager: res[0].Manager });
this.setState({ User_Name: res[0].User_Name });
this.setState({ Business_Unit: res[0].Business_Unit });
this.setState({ Organization_Info: res[0].Organization_Info });
this.setState({ BU_Head: res[0].BU_Head });
console.log(res[0].Title);
console.log(res[0].Organization_Info);
console.log(res)
}).catch((err) => {
console.log(err);
})
console.log(this.state.Title)
console.log(this.state.Manager)
4-- in this.state under export default initialize the value name eg:
export default class Award extends React.Component<any, any> {
constructor(props) {
super(props);
this.state = {
EmpName: "",
};
}
5-- pass the value to the input field eg:
<div className="col">
{this.state.EmpName}
<Body1> </Body1>
</div>