I am learning react and i was trying to make a react class based component in which i am trying to fetch data from articles array that has data of news articles such as title,description, urlToimage, url. i was trying to cut short the title and description string to a maximum length of 40 and 80 respectively and i tried doing this with the use of slice as you can see but met with the error mentioned below. I also made sure that the title and description are of string or array datatypes to avoid any datatype incurred errors both title and description are written as "title" : "content inside". Rest of the code was running fine without slice and was showing all the data as intended. I don't know if the syntax have changed or not as i am following a tutorial from 2021.
{this.state.articles.map((elements) => {
let title = elements.title;
let description = elements.description;
return <div className="col-md-4 my-3" key={elements.url}>
<NewsItem title={title.slice(0,45)} description={description.slice(0,80 )} imageUrl={elements.urlToImage} newsUrl={elements.url}></NewsItem>
</div>
})}
react-refresh-runtime.development.js:315 Uncaught TypeError: Cannot read properties of null (reading 'slice')