import { Web } from "sp-pnp-js"; import pnp from "sp-pnp-js"; interface ISPVehicule { Title: string; Marque: string; Modele: string; Vitesse: string; Poid: string; } export default class ReactPnP extends React.Component<IReactPnPProps, {}> { private vehiculeList: ISPVehicule[]; private web; constructor(props) { super(props); this.web = new Web(this.props.contextUrl); this.web.lists.getByTitle("Voitures").items.get() .then((vehicules: ISPVehicule[]) => { this.vehiculeList = vehicules }); console.log("vehicule : " + this.vehiculeList); } ....
I would like to store the Get Method result in the VehiculeList property. However, it does not work the way I have done it. In fact, I am getting this error message:
“vehicule : undefined”
Do you know what I am doing wrong?
Eventually, I would like to use this property to display its content by injecting the following code in the Render Method :
{this.vehiculeList.map((vehicule) =>{ return (<div>{vehicule.Title}</div>); } )}.