3

I am getting SharePoint list items using framework react with following code:

Developing SharePoint Framework Web Parts Using ReactJS

import * as React from 'react';  
import { css } from 'office-ui-fabric-react';  
import styles from './Splistitems.module.scss';  
import { ISplistitemsProps } from './ISplistitemsProps';  
import * as jquery from 'jquery';   

export interface ISplistitemsState{  
  items:[  
        {  
          "Title":string           
        }]  
}  


export default class Splistitems extends React.Component<ISplistitemsProps, void> {
    public constructor(props: ISplistitemsProps, state: ISplistitemsState){  
        super(props);  
        this.state = {  // This `this.state` throws error
          items: [  
            {  
              "Title": ""           
            }  
          ]  
        };  
      } 

public componentWillMount(){ 
//..
//..
}
public render(): React.ReactElement<IUpcomingEventsProps> {
//..
//..
}
}

Here, line this.state throws following error:

Type '{ items: { "Title": string; }[]; }' is not assignable to type 'void'.

what is the problem ??

2
  • can you change super(props); to super(); and check ? Commented Jul 11, 2017 at 12:39
  • Not working.... Commented Jul 11, 2017 at 12:45

1 Answer 1

3

There will be return type ISplistitemsState instead of void in Splistitems class.

Change following line

export default class Splistitems extends React.Component<ISplistitemsProps, void> {

To

export default class Splistitems extends React.Component<ISplistitemsProps, ISplistitemsState> {
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.