actually Im working with SPFX webpart using React, really don
t understand what is the issue here, but when I debug it shows the blow screenshot.
trying to get the SP list items in SPFX webpart using React, during the map it getting error.
please assist me using the below piece of code.
public render(): React.ReactElement<IGetSpListItemsProps> {
return(
<div className={"styles.welcome"}>
<table >
{
this.state.listitems.map(function (listitem, listitemkey){
let fullurl: string = `${GetSpListItems.siteurl}/lists/SampleList/DispForm.aspx?ID=${listitem.ID}`;
return(
<tr>
<td><a className={styles.label} href={fullurl}>{listitem.Title}</a></td>
<td className={styles.label}> {listitem.ID}</td>
</tr>)})}
</table>
Here is the video where I have gone through as per the same I have followed but when I try it shows undefined error
text
2
Answers
change your code to this:
map
method belongs to array in Javascript. In your case, value of variable isundefined
and for that variable valuemap
method is being applied. Thus, you are seeing that error as being an invalid value formap
method.In order to resolve/prevent this error, what we can do is that, before assigning variable to
map
method, we will do separate conditional check for that variable value to make sure that it will be a valid array. With that, you won’t be having that error.