Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use messages from props instead of state #2437

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@types/react": "~16.9.35",
"@types/react-native": "~0.63.2",
"@types/react-test-renderer": "16.9.2",
"@types/uuid": "3.4.9",
"@types/uuid": "9.0.2",
"@typescript-eslint/eslint-plugin": "5.18.0",
"@typescript-eslint/parser": "5.18.0",
"babel-jest": "27.5.1",
Expand Down Expand Up @@ -75,7 +75,7 @@
"react-native-parsed-text": "0.0.22",
"react-native-typing-animation": "0.1.7",
"use-memo-one": "1.1.3",
"uuid": "3.4.0"
"uuid": "9.0.0"
},
"peerDependencies": {
"react": "*",
Expand Down
11 changes: 4 additions & 7 deletions src/GiftedChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
ViewStyle,
} from 'react-native'
import { LightboxProps } from 'react-native-lightbox-v2'
import uuid from 'uuid'
import { v4 as uuidV4 } from 'uuid'
import { Actions, ActionsProps } from './Actions'
import { Avatar, AvatarProps } from './Avatar'
import Bubble from './Bubble'
Expand Down Expand Up @@ -219,13 +219,12 @@ export interface GiftedChatProps<TMessage extends IMessage = IMessage> {
): boolean
}

export interface GiftedChatState<TMessage extends IMessage = IMessage> {
export interface GiftedChatState {
isInitialized: boolean
composerHeight?: number
messagesContainerHeight?: number | Animated.Value
typingDisabled: boolean
text?: string
messages?: TMessage[]
}

function GiftedChat<TMessage extends IMessage = IMessage>(
Expand All @@ -236,7 +235,7 @@ function GiftedChat<TMessage extends IMessage = IMessage>(
text = undefined,
initialText = '',
isTyping,
messageIdGenerator = () => uuid.v4(),
messageIdGenerator = () => uuidV4(),
user = {},
onSend = () => {},
locale = 'en',
Expand Down Expand Up @@ -279,15 +278,13 @@ function GiftedChat<TMessage extends IMessage = IMessage>(
messagesContainerHeight: undefined,
typingDisabled: false,
text: undefined,
messages: undefined,
})

useEffect(() => {
isMountedRef.current = true

setState({
...state,
messages,
// Text prop takes precedence over state.
...(text !== undefined && text !== state.text && { text: text }),
})
Expand Down Expand Up @@ -473,7 +470,7 @@ function GiftedChat<TMessage extends IMessage = IMessage>(
onKeyboardDidShow: onKeyboardDidShow,
onKeyboardDidHide: onKeyboardDidHide,
}}
messages={state.messages}
messages={messages}
forwardRef={messageContainerRef}
isTyping={isTyping}
/>
Expand Down
15 changes: 10 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2450,10 +2450,10 @@
resolved "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz"
integrity sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==

"@types/uuid@3.4.9":
version "3.4.9"
resolved "https://registry.npmjs.org/@types/uuid/-/uuid-3.4.9.tgz"
integrity sha512-XDwyIlt/47l2kWLTzw/mtrpLdB+GPSskR2n/PIcPn+VYhVO77rGhRncIR5GPU0KRzXuqkDO+J5qqrG0Y8P6jzQ==
"@types/uuid@9.0.2":
version "9.0.2"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.2.tgz#ede1d1b1e451548d44919dc226253e32a6952c4b"
integrity sha512-kNnC1GFBLuhImSnV7w4njQkUiJi0ZXUycu1rUaouPqiKlXkh77JKgdRnTAp1x5eBwcIwbtI+3otwzuIDEuDoxQ==

"@types/yargs-parser@*":
version "15.0.0"
Expand Down Expand Up @@ -7822,7 +7822,12 @@ [email protected]:
resolved "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz"
integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=

[email protected], uuid@^3.3.2:
[email protected]:
version "9.0.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5"
integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==

uuid@^3.3.2:
version "3.4.0"
resolved "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
Expand Down