npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@amityco/ts-sdk-react-native

v6.32.2

Published

Amity Social Cloud Typescript SDK

Downloads

25,374

Readme

Amity Social Cloud Typescript SDK for React-Native

Getting Started

  • With npm: npm install @amityco/ts-sdk-react-native
  • With yarn: yarn add @amityco/ts-sdk-react-native

Runtime support

  • Modern browsers (es2017 compliant)
  • NodeJS (via esm imports)
  • React-Native

Creating a client instance

To connect your users to our platform, you need to create a client instance and connect it.

import { Client } from '@amityco/ts-sdk-react-native';

(async () => {
  const sessionHandler: Amity.SessionHandler = {
    sessionWillRenewAccessToken(renewal: Amity.Renewal) {
      renewal.renew();
      /*
       * If using an auth token
       *
       * try {
       *  renew.renewWithAuthToken(authToken)
       * } catch() {
       *  sdk will try to renew again at a later time
       *
       *  renew.unableToRetrieveAuthToken()
       * }
       */
    },
  };
  const client = Client.createClient(API_KEY, API_REGION);

  let isConnected = await Client.login({ userId: USER_ID }, sessionHandler);
})();

The API_KEY and API_REGION are given at the time you create an application in the Amity Portal.

You can listen to disconnection by using the onClientDisconnected function:

import { Client } from '@amityco/ts-sdk-react-native';

const unsub = Client.onClientDisconnected(() => (isConnected = false));

The unsub's return value is a dispose function which is used to clean the memory of your client's application. It's been designed to fit perfectly with React, in a useEffect such as:

useEffect(() => onClientConnected(() => setConnected(false)), [])

## Going further

### Domain types

All the necessary types are automatically exposed in the `Amity` namespace. As long as you import the SDK once, the namespace will be available in your workspace. You can start to type `Amity.` and see the list of types in your intellisense after having imported the SDK in any file of your project.

### Subscribing to real time events

We expose a couple of functions for your to receive simply the events that could fire from our servers, for example, if another user would change their display name, or if a channel would receive a new message.

The `subscribeTopic` method retuns an unsubscriber that can be called on clean up to stop recieving further events.

```ts
import { subscribeTopic, getUserTopic } from '@amityco/ts-sdk-react-native'

const unsub = subscribeTopic(getUserTopic({} as Amity.User))

Observe an object using Live Object

For an 'all-in-one' approach, we expose live objects, which allow to fetch an object and register to its changes all at once. This has been designed to fit with React's useState and useEffect:

import { UserRepository } from '@amityco/ts-sdk-react-native'

const Component = ({ userId }: { userId: string }) => {
  const [user, setUser] = useState<Amity.User>({})

  useEffect(() => UserRepository.getUser(userId, ({ data: user, loading, error }) => {
    // ensure you call unsub() on cleanup or unmount
    const unsub = subscribeTopic(getUserTopic(user))

    setUser(user)
  }), [userId])

  return <div>{JSON.stringify(user, null, 2)}
}

Observe a collection using Live Collection

Similar to the concept of live object, we expose live collection, which allow to fetch a collection and register to its changes all at once. This has been designed to fit with React's useState and useEffect:

import { UserRepository.getUsers } from '@amityco/ts-sdk-react-native'

const Component = () => {
  const [users, setUsers] = useState<Amity.User[]>({})

  useEffect(() => UserRepository.getUsers({}, ({ data, loading, error, nextPage, hasNextPage }) => {
    // ensure you call unsub() on cleanup or unmount
    // Subscribe to each user in collection for getting real time updates

    setUsers(users)
  }), [userId])

  return <div>{JSON.stringify(user, null, 2)}
}

Documentation

To see the comprehensive documentation please visit our documentation page.

If you have any questions, you can visit our forum.