React: Split String in Render HTML
Error message:
TypeError: Cannot read property 'split' of null
Solution:
Insert a question mark after the variable before split()
(this.state.keywords)?.split(";").map(keyword => <a href={this.baseURL + "?k=" + keyword}> {keyword}</a>
|
To avoid a zero variable, you can use a ? append behind a variable and a function, which will only run it if a value exists.
TypeError: Cannot read property 'split' of null Article.render D:/Programmierung/Web/Demo/CodeDocu/CodeDocu/ClientApp/src/components/Article.js:98 95 | </div>
View compiled This screen is visible only in development. It will not appear if the
app crashes in production.
|
React Code with .split(";").map..