A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.mongodb.com/docs/atlas/device-sdks/sdk/react-native/app-services/call-a-function/ below:

Call a Function - React Native SDK - Atlas Device SDKs

The examples in this section demonstrate calling a simple Atlas Function named sum that takes two arguments, adds them, and returns the result:

exports = function(a, b) {  return a + b;};
  1. In an App Services App, define an Atlas Function.

  2. In your client project, initialize the App client.

  3. Then, authenticate a user in your React Native project.

Important

Make sure to sanitize client data to protect against code injection when using Functions.

To call a function, you can either pass its name and arguments to User.callFunction() or call the function as if it were a method on the User.functions property.

import React from 'react';import {useUser} from '@realm/react';function Addition() {    const user = useUser();  const addNumbers = async (numA: number, numB: number) => {            const sumMethod1 = await user?.callFunction('sum', numA, numB);        const sumMethod2 = await user?.functions.sum(numA, numB);        console.log(sumMethod1 === sumMethod2);   };  }

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4