GeekyAnts / GeekyAnts/NativeBase

when use the useToast, state value is initialized

Open
#5,802 1 comment 0 reactions 0 assignees View on GitHub
bug triage v3
Dominant language
TypeScript
Stars
20.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

### Description

when use the useToast, state value is initialized

### CodeSandbox/Snack link

/

### Steps to reproduce

Below my code

// useToast.tsx
```
import React from 'react';
import {useToast} from 'native-base';
import ToastMessage from '~/components/common/toast/ToastMessage';
import {TextStyle, ViewStyle} from 'react-native';

type ToastShowProps = {
message: string;
leftElement?: JSX.Element;
rightElement?: JSX.Element;
textStyle?: TextStyle;
viewStyle?: ViewStyle;
justifyContent?: 'space-between' | 'center';
};

/**
*@description toast 훅 생성
*/
function useToastShow() {
const toast = useToast();

const toastShow = (props: ToastShowProps) => {
return toast.show({
render: () => {
return ;
},
duration: 3000,
});
};

return {toastShow, toast};
}

export default useToastShow;

```

// EmailLogin.tsx
```
import {VStack} from 'native-base';
import React, {useState} from 'react';
import {SafeAreaView} from 'react-native-safe-area-context';
import {colors} from '~/theme/theme';
import {TextInput} from 'react-native';
import RedActiveLargeButton from '~/components/common/button/RedActiveLargeButton';
import {APP_HEIGHT} from '~/utils/dimension';
import {HEADER_HEIGHT} from '~/constants/heights';
import useToastShow from '~/hooks/useToast';

function EmailLogin() {
const {toastShow} = useToastShow();

const [loginForm, setLoginForm] = useState('');

const onLogin = async () => {
toastShow({
message: 'Test',
});
};

return (




setLoginForm(text)}
/>






);
}

export default EmailLogin;

```

when
- problem
If enter the input before click the toast output button, the input state(loginForm) is initialized.

- want
input state(loginForm) is no initialized

### NativeBase Version

3.4.18

### Platform

- [X] Android
- [ ] CRA
- [ ] Expo
- [X] iOS
- [ ] Next

### Other Platform

_No response_

### Additional Information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.