跳至主要內容
版本:v18.0.0

useRelayEnvironment

useRelayEnvironment

此 Hook 用於存取由 RelayEnvironmentProvider 設定的 Relay 環境

const React = require('React');

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

function MyComponent() {
const environment = useRelayEnvironment();

const handler = useCallback(() => {
// For example, can be used to pass the environment to functions
// that require a Relay environment.
commitMutation(environment, ...);
}, [environment])

return (...);
}

module.exports = MyComponent;

此頁面有幫助嗎?

協助我們讓網站變得更好 回答幾個簡單的問題.