I want to get a sharepoint list and assign it to my list 'items' which of type is IExampleItem, but I don't really know how to do it; I tried the following code but it gives me an error, my list 'items' is not compatible with what my
_getFacItems return Promise《T》 so it not same as IExampleItem.
I did sample test demo in my github project below, I bind data in component not in webpart directly, while it might be helpful for you.
While there is nothing technically wrong with loading the items in the FaqWebPart, I prefer to load it in the component for performance reasons. That way, it appears that the web part is faster (even if it isn't, really) by first rendering an empty list, and rendering a filled list once the items are loaded. You can even be fancy and add a 'loading' message, a spinner, or a shimmer to your list.
The trick to solve the error you get is to map the returned list items (which are of type
any when they get returned) to a
IExampleItem in your original code). In this example, assigned the returned items to a
const variable to make it easier to read the code.
Here is how I would change the code to do this:
Full disclaimer: I did not build or run this code. There may be errors, but I should demonstrate the concept.
I hope this helps?