FirebaseExtended / reactfire

Hooks, Context Providers, and Components that make it easy to interact with Firebase.
https://firebaseopensource.com/projects/firebaseextended/reactfire/
MIT License
3.52k stars 401 forks source link

Add support for Cloud Functions for Firebase #444

Closed jhuleatt closed 3 years ago

jhuleatt commented 3 years ago

Code sample

function Calculator() {
  const functions = useFunctions();
  const remoteCalculator = httpsCallable(functions, 'calculate');

  const [calculationResult, setResult] = useState(null);

  async function handleButtonClick(firstNumber, secondNumber, operator) {
    const remoteCalculatorResponse = await remoteCalculator({ firstNumber, secondNumber, operator });
    setResult(remoteCalculatorResponse.data);
  }

  if (!calculationResult) {
    return <button onClick={() => handleButtonClick(1, 2, '+')}>Click me to add 1 + 2</button>;
  } else {
    return <pre>{calculationResult}</pre>;
  }
}

fixes #330

jhuleatt commented 3 years ago

~Tests are failing because I need to update the workflow yaml to run npm install in the functions directory~

Tests are passing now!