relay-environment

Relay Environment Provider

Relay μ»΄ν¬λ„ŒνŠΈλ₯Ό λ Œλ”λ§ν•˜κΈ° μœ„ν•΄ μ–΄ν”Œλ¦¬μΌ€μ΄μ…˜μ˜ root 에 RelayEnvironmentProvider μ»΄ν¬λ„ŒνŠΈλ₯Ό μ„ μ–Έν•΄μ•Ό ν•œλ‹€.

const {RelayEnvironmentProvider} = require('react-relay');
const Environment = require('MyEnvironment');

function Root() {
  return (
    <RelayEnvironmentProvider environment={Environment}>
      {/*... */}
    </RelayEnvironmentProvider>
  );
}

RelayEnvironmentProvider λŠ” λͺ¨λ“  μžμ‹ Relay μ»΄ν¬λ„ŒνŠΈμ—μ„œ μ‚¬μš©ν•  수 있고 Relay λ₯Ό μ‚¬μš©ν•˜λŠ”λ° ν•„μš”ν•œ ν™˜κ²½μ„ μ œκ³΅ν•œλ‹€.

Relay Environment μ ‘κ·Όν•˜κΈ°

RelayEnvironmentProvider μ»΄ν¬λ„ŒνŠΈμ˜ μžμ‹ μ»΄ν¬λ„ŒνŠΈμ—μ„œ relay ν™˜κ²½μ— μ ‘κ·Όν•˜κΈ° μœ„ν•΄ useRelayEnvironment Hook을 μ‚¬μš©ν•œλ‹€.

const {useRelayEnvironment} = require('react-relay');

function UserComponent(props: Props) {
  const environment = useRelayEnvironment();

  const handler = useCallback(() => {
      // relay ν™˜κ²½μ„ μš”κ΅¬ν•˜λŠ” ν•¨μˆ˜μ—κ²Œ environment 을 전달할 수 μžˆλ‹€
      commitMutation(environment, ...);
  }, [environment])

  return (...);
}

Last updated