이 포스트는 Expo 환경, react-native-toast-message↗ 2.2.1 버전을 기준으로 작성되었습니다. React Native Cli 환경에서도 동일한 방법으로 적용할 수 있습니다.

npm install react-native-toast-message/app/_layout.tsx 파일에 다음과 같이 설정합니다.import Toast from 'react-native-toast-message';
 
export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <View>
      {children}
      <Toast />
    </View>
  );
}app.tsx 파일에 다음과 같이 설정합니다.import Toast from 'react-native-toast-message';
 
export function App( props: any ) {
  return (
    <>
      {/* ... */}
      <Toast />
    </>
  );
}import Toast from 'react-native-toast-message';
import { Button } from 'react-native'
 
export function Page() {
  const showToast = () => {
    Toast.show({
      type: 'success',
      text1: 'Hello',
      text2: 'This is some something 👋'
    });
  }
 
  return (
    <Button
      title='Show toast'
      onPress={showToast}
    />
  )
}/app/_layout.tsx 파일(Expo 환경) 또는 app.tsx 파일(React Native Cli 환경)에 다음과 같이 설정합니다.
이 예시에서는 세 가지 토스트 메시지를 표시하고 있습니다. success, error 타입은 기본 토스트 메시지를 수정해 사용하고, tomatoToast 타입은 커스텀 토스트 메시지를 사용합니다.import Toast, { BaseToast, ErrorToast } from 'react-native-toast-message';
 
const toastConfig = { // config 변수 추가
  success: (props) => (
    <BaseToast
      {...props}
      style={{ borderLeftColor: 'pink' }}
      contentContainerStyle={{ paddingHorizontal: 15 }}
      text1Style={{
        fontSize: 15,
        fontWeight: '400'
      }}
    />
  ),
  error: (props) => (
    <ErrorToast
      {...props}
      text1Style={{
        fontSize: 17
      }}
      text2Style={{
        fontSize: 15
      }}
    />
  ),
	tomatoToast: ({ text1, props }) => (
    <View style={{ height: 60, width: '100%', backgroundColor: 'tomato' }}>
      <Text>{text1}</Text>
      <Text>{props.uuid}</Text>
    </View>
  )
}
 
export default function Page() {
  return (
    <View>
      {children}
      <Toast config={toastConfig} />
    </View>
  );
}import Toast from 'react-native-toast-message';
import { Button } from 'react-native'
 
export function Page() {
  const showToast = () => {
    Toast.show({
			type: 'tomatoToast',
			props: { uuid: 'uuid example' }
    });
  }
 
	const showErrorToast = () => {
		Toast.show({
			type: 'error',
			text1: 'Error',
			text2: 'This is some something 👋'
		});
	}
 
  return (
    <Button	
      title='Show toast'
      onPress={showToast}
    />
  )
}