Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to use this package :

https://www.npmjs.com/package/react-native-pell-rich-editor

And I have the following code :

import { useState, useRef } from "react";
import { RFPercentage } from "react-native-responsive-fontsize";
import BottomSheet from "@gorhom/bottom-sheet";
import {
  StyleSheet,
  View,
  Text,
  SafeAreaView,
  ScrollView,
} from "react-native";
import {
  actions,
  RichEditor,
  RichToolbar,
} from "react-native-pell-rich-editor";

export default function Publish() {

  const postSheetRef = useRef(null);
  const richText = useRef();

  const snapPoints = ["90%"];
    
  };

 return (
    <>
      <View style={styles.container}>
        <View style={styles.publishHeader}>
          <Text style={styles.titleHeader}>Publier un post</Text>
        </View>
        <BottomSheet
          ref={postSheetRef}
          snapPoints={snapPoints}
          handleIndicatorStyle={{ display: "none" }}
        >
          <View style={styles.main}>
            <SafeAreaView>
              <ScrollView>
                  <RichEditor
                    ref={richText}
                    onChange={(descriptionText) => {
                      console.log("descriptionText:", descriptionText);
                    }}
                  />
              </ScrollView>

              <RichToolbar
                editor={richText}
                actions={[
                  actions.setBold,
                  actions.setItalic,
                  actions.setUnderline,
                  actions.heading1,
                ]}
                iconMap={{
                  [actions.heading1]: ({ tintColor }) => (
                    <Text style={[{ color: tintColor }]}>H1</Text>
                  ),
                }}
              />
            </SafeAreaView>
          </View>
        </BottomSheet>
      </View>
    </>
  );
}


I get this error :

JavaScript
Function components cannot be given refs


It concerns the Rich Editor component.

But I just followed the documentation, so I can't understand why.

According to the github repo of the package, RichEditor seems to be a class component ... Anyway, the documentation tells me to use Ref.

What I have tried:

I tried this :


<RichEditor
                ref={(r)=>{richText.current = r}}
                onChange={(descriptionText) => {
                  console.log("descriptionText:", descriptionText);
                }}
              />


But it did not help.

I am working with Expo.

How can I solve this ? This is the only package I have found that is compatible with Expo so I need to make it work ^^.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900