admin管理员组文章数量:1023230
I want to add locale to my react-native-gifted-chat, because the chats do not show up one after the other, I am guessing because of time zones.
I added Locale to my gifted chat:
import en from 'dayjs/locale/en'
render() {
return (
<View style={{backgroundColor: '#000000', flex: 1}}>
<GiftedChat
showUserAvatar={true}
isTyping={this.state.isTyping}
renderUsernameOnMessage={true}
messages={this.state.messages}
onSend={message => this.onSend(message)}
scrollToBottom
locale = { en } <-----------------------------
showAvatarForEveryMessage = {false}
showUserAvatar= {true}
dateFormat = 'll'
timeFormat = 'LT'
placeholder = "Talk to people..."
onPressAvatar={user => this.getProfile(user)}
/>
</View>
)
But now I get the error:
TypeError: undefined is not an object (evaluating 'n[M].replace')
Is this because I am using the wrong type of import, or is the existing chats the issue, and do I need to delete them for things to work?
I want to add locale to my react-native-gifted-chat, because the chats do not show up one after the other, I am guessing because of time zones.
I added Locale to my gifted chat:
import en from 'dayjs/locale/en'
render() {
return (
<View style={{backgroundColor: '#000000', flex: 1}}>
<GiftedChat
showUserAvatar={true}
isTyping={this.state.isTyping}
renderUsernameOnMessage={true}
messages={this.state.messages}
onSend={message => this.onSend(message)}
scrollToBottom
locale = { en } <-----------------------------
showAvatarForEveryMessage = {false}
showUserAvatar= {true}
dateFormat = 'll'
timeFormat = 'LT'
placeholder = "Talk to people..."
onPressAvatar={user => this.getProfile(user)}
/>
</View>
)
But now I get the error:
TypeError: undefined is not an object (evaluating 'n[M].replace')
Is this because I am using the wrong type of import, or is the existing chats the issue, and do I need to delete them for things to work?
Share Improve this question asked Jan 26, 2021 at 4:23 kalculatedkalculated 3196 silver badges27 bronze badges1 Answer
Reset to default 4Looking at the documentation, it appears you need to import the locale file separately.
First you need to import daysjs:
import dayjs from 'dayjs';
Then you need to import the locale you want:
import 'dayjs/locale/en'
This appears to have a global mutation side effect (bad) of making that locale available for formatting.
In your prop, pass in locale="en"
Then in your ponent (if you own it) you can use dayjs(date).locale(this.props.locale).format()
Daysjs doesn't look like a well designed library, because imports shouldn't have side effects like this.
I want to add locale to my react-native-gifted-chat, because the chats do not show up one after the other, I am guessing because of time zones.
I added Locale to my gifted chat:
import en from 'dayjs/locale/en'
render() {
return (
<View style={{backgroundColor: '#000000', flex: 1}}>
<GiftedChat
showUserAvatar={true}
isTyping={this.state.isTyping}
renderUsernameOnMessage={true}
messages={this.state.messages}
onSend={message => this.onSend(message)}
scrollToBottom
locale = { en } <-----------------------------
showAvatarForEveryMessage = {false}
showUserAvatar= {true}
dateFormat = 'll'
timeFormat = 'LT'
placeholder = "Talk to people..."
onPressAvatar={user => this.getProfile(user)}
/>
</View>
)
But now I get the error:
TypeError: undefined is not an object (evaluating 'n[M].replace')
Is this because I am using the wrong type of import, or is the existing chats the issue, and do I need to delete them for things to work?
I want to add locale to my react-native-gifted-chat, because the chats do not show up one after the other, I am guessing because of time zones.
I added Locale to my gifted chat:
import en from 'dayjs/locale/en'
render() {
return (
<View style={{backgroundColor: '#000000', flex: 1}}>
<GiftedChat
showUserAvatar={true}
isTyping={this.state.isTyping}
renderUsernameOnMessage={true}
messages={this.state.messages}
onSend={message => this.onSend(message)}
scrollToBottom
locale = { en } <-----------------------------
showAvatarForEveryMessage = {false}
showUserAvatar= {true}
dateFormat = 'll'
timeFormat = 'LT'
placeholder = "Talk to people..."
onPressAvatar={user => this.getProfile(user)}
/>
</View>
)
But now I get the error:
TypeError: undefined is not an object (evaluating 'n[M].replace')
Is this because I am using the wrong type of import, or is the existing chats the issue, and do I need to delete them for things to work?
Share Improve this question asked Jan 26, 2021 at 4:23 kalculatedkalculated 3196 silver badges27 bronze badges1 Answer
Reset to default 4Looking at the documentation, it appears you need to import the locale file separately.
First you need to import daysjs:
import dayjs from 'dayjs';
Then you need to import the locale you want:
import 'dayjs/locale/en'
This appears to have a global mutation side effect (bad) of making that locale available for formatting.
In your prop, pass in locale="en"
Then in your ponent (if you own it) you can use dayjs(date).locale(this.props.locale).format()
Daysjs doesn't look like a well designed library, because imports shouldn't have side effects like this.
本文标签: javascriptGetting error when I import 39dayjslocalen39Stack Overflow
版权声明:本文标题:javascript - Getting error when I import 'dayjslocalen'? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745543548a2155290.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论