Using react native module (with native code) in expo project

Viewed 120

I am working in an existing expo project (expo version 42.0.1 ) and I am unable to get this package working. It says in the package readme that it doesn't work with Expo, because it uses native code. But the readme is from a year ago and I thought Expo sdk42 allows you to use native modules now when you build your own custom client?

Does anyone know what I need to do to get this package working?

https://github.com/KjellConnelly/react-native-shared-group-preferences

Here's what i tried so far...

I added to my project with yarn add react-native-shared-group-preferences

And in App.js :

import 'expo-dev-client';
import React from 'react';
import { styles } from './src/components/CommonStyles';
import { useState } from 'react';
import { View, TextInput, Text } from 'react-native';
import SharedGroupPreferences from 'react-native-shared-group-preferences';

export default function App() {
  const [inputText, setInputText] = useState('');
  const widgetData = {
    displayText: inputText,
  };

  const appGroupIdentifier = 'group.com.myproject.newwidget';

  const handleSubmit = async () => {
    try {
      console.log('handleSubmit' + widgetData + appGroupIdentifier);
      await SharedGroupPreferences.setItem(
        'savedData', // this is a key to pull from later in Swift
        widgetData,
        appGroupIdentifier
      );
    } catch (error) {
      console.log({ error });
    }
  };

  return (
...
)

when I run the project with expo start and i to open iphone simulator,

I get this error: null is not an object (evaluating 'RNReactNativeSharedGroupPreferences.setItem')"

What am I doing wrong? Any help very much appreciated. Thanks

0 Answers
Related