如何添加< br>在两个字符串之间的reactjs中标记? [英] How to add a <br> tag in reactjs between two strings?
本文介绍了如何添加< br>在两个字符串之间的reactjs中标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用反应。我想在字符串之间添加换行符< br>
I am using react. I want to add a line break <br>
between strings
'没有结果'和'请尝试另一个搜索字词。'。
'No results' and 'Please try another search term.'.
我试过'没有结果。< br>请尝试其他搜索字词。'
但它不起作用,我需要在html中添加< br>
。
but it does not work, I need to add the <br>
in the html.
任何想法如何解决?
render() {
let data = this.props.data;
let isLoading = this.props.isLoading;
let isDataEmpty = Object.entries(data).length === 0;
let movieList = isLoading ? <Loader /> : isDataEmpty ? 'No results. Please try another search term.' :
Object.entries(data).map((movie, index) => <MovieTile key={index} {...movie[1]} />);
return (
<div className='movieList'>{movieList}</div>
);
}
推荐答案
你应该使用JSX而不是字符串:
You should use JSX instead of string:
<div>No results.<br />Please try another search term.</div>
因为每个jsx应该有1个包装器我添加了
< div>
字符串的包装器。
这是在你的代码中:
render() {
let data = this.props.data;
let isLoading = this.props.isLoading;
let isDataEmpty = Object.entries(data).length === 0;
let movieList = isLoading ? <Loader /> : isDataEmpty ? <div>No results.<br />Please try another search term.</div> :
Object.entries(data).map((movie, index) => <MovieTile key={index} {...movie[1]} />);
return (
<div className='movieList'>{movieList}</div>
);
}
这篇关于如何添加< br>在两个字符串之间的reactjs中标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文