我有 tsx 文件返回这个:
return (
<>
<Container>
data.map((item, i) => {
let fullNameLetters = item.fullName.substring(0, 2);
if (item.fullName.indexOf(' ') > 0) {
fullNameLetters = item.fullName.split(' ')[0][0].toUpperCase() + item.fullName.split(' ')[1][0].toUpperCase();
}
return (
<Card {...item} key={i} nameInitials={fullNameLetters} content={item.content} />
);
})
</Container>
</>
)
我的 MapStateToProps 是这样的:
const mapStateToProps = (state: ApplicationState) => ({
data: state.persons.data
});
所以我的问题是如何将此代码放入 mapStateToProps?:
data.map((item, i) => {
let fullNameLetters = item.fullName.substring(0, 2);
if (item.fullName.indexOf(' ') > 0) {
fullNameLetters = item.fullName.split(' ')[0][0].toUpperCase() + item.fullName.split(' ')[1][0].toUpperCase();
}