Issue with Dialogue in React Native - The property 'children' is not found in the types 'intrinsicAttributes' and '

I attempted to utilize this sample code to create an alert dialog in my react native app, but I encountered an error on Dialog (marked with ***) stating

TS2322: Type '{ children: Element[]; visible: boolean; onDismiss: () => void; }' is not compatible with type 'IntrinsicAttributes & DialogProps'. Property 'children' does not exist on type 'IntrinsicAttributes & DialogProps'.

Moreover, upon running the app and clicking the open alert dialog button, I received an error message within the app saying Render Error: usePortalContext must be used within a Portal Context, which left me puzzled. The code snippet for the dialog was directly copied from the documentation available at here. Despite following the instructions, it did not work as expected.

 import React, {useState} from 'react';
import {
  Button,
  Dialog,
  DialogHeader,
  DialogContent,
  DialogActions,
  Text,
} from '@react-native-material/core';

const Dialog_ = () => {
  const [visible, setVisible] = useState(false);

  return (
    <>
      <Button
        title="Open Alert Dialog"
        style={{margin: 16}}
        onPress={() => setVisible(true)}
      />
      <Dialog*** visible={visible} onDismiss={() => setVisible(false)}> 
        <DialogHeader title="Dialog Header" />
        <DialogContent>
          <Text>
            Lorem ipsum dolor sit amet, consectetur adipisicing elit. Earum
            eligendi inventore, laboriosam laudantium minima minus nesciunt
            pariatur sequi.
          </Text>
        </DialogContent>
        <DialogActions>
          <Button
            title="Cancel"
            compact
            variant="text"
            onPress={() => setVisible(false)}
          />
          <Button
            title="Ok"
            compact
            variant="text"
            onPress={() => setVisible(false)}
          />
        </DialogActions>
      </Dialog>
    </>
  );
};

export default Dialog_;

Answer №1

After encountering the same error, I carefully examined the example and noticed that the App was enclosed within a Provider component:

const AppProvider = () => (
  <Provider>
    <App />
  </Provider>
);

I made sure to add the Provider component in my function as well as in the import statement, and then the Dialog was displayed correctly.

Answer №2

Remember to utilize the Provider component from react-native-material library.

import { Provider } from "@react-native-material/core";
const AppProvider = () => (
    <Provider>
       <App />
    </Provider>
);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Discovering the magic of nesting maps in React-Native without the need for

I am currently developing a react-native app that retrieves its data through an API. I am working on implementing a new feature where the information is grouped by date. The JSON data structure sent by the API looks like this: { "channel_count" ...

Update the page content once the popover is closed. Working with IONIC 3

In my application, there are 4 tabs, each displaying different data based on a specific configuration. The header of the page includes a popover component with settings options. When a user adjusts the settings and returns to a tab page, the content on th ...

Show the subjects' names and their scores once they have been added to a fresh array

Here is my unique code snippet: let fruits: string[] = ['Apple', 'Banana', 'Orange', 'Grapes', 'Mango']; function capitalize(fruit: string) { return fruit.toUpperCase(); } let uppercaseFruits = fruits ...

Experiencing an issue with Jest - Error: unable to access property 'forEach' of null

After watching some tutorials, I decided to create a sample project in Jest for writing tests. In a TypeScript file, I included a basic calculation function like this: Calc.cs export class Calc { public add(num1: number, num2: number): number { ...

Determine the difference between dates using Angular 2's array filtering function

Here's a way to get the current time in seconds: let currentTimeInSeconds = new Date().getTime() / 1000; I have an array containing objects with an expirationDate property that returns expiration time in seconds. I can find the bills that have expir ...

When defining a stripe in TypeScript using process.env.STRIPE_SECRET_KEY, an error of "string | undefined" is encountered

Every time I attempt to create a new stripe object, I encounter the error message "Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string& ...

What steps can be taken to ensure the visibility and accessibility of two vertically stacked/overlapped Html input elements in HTML?

I have encountered a challenge with my HTML input elements. There are two input elements that overlap each other, and I would like to make both inputs visible while only allowing the top input to be editable. I have tried several approaches involving z-ind ...

Understanding how to integrate compiled Typescript AMD modules into the Magento2 platform

I have been working on integrating Typescript support into Magento 2 to modernize it. Everything seems to compile correctly, but I am facing an issue with loading it. My require-config.js file looks like this: var config = { deps: [ "web/js/a ...

Immutable parameter in constructor

While analyzing some TypeScript code, I stumbled upon a peculiar declaration within a class definition: constructor(readonly constructorParam : Type) { // no assignment of constructorParam here } Surprisingly, constructorParam is still being used as usu ...

Can we resolve the warnings arising from third party dependencies in a React application?

After running the pnpm install command to set up dependencies for a react app today, I encountered the following warning messages: > pnpm install  WARN  deprecated <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f18287969 ...

Retrieving properties of a universal function

I am facing a challenge in creating a class that accepts a factory function as one of its parameters in the constructor, which is then used to create instances of another class. The implementation below is written in JavaScript. // item to create class Ite ...

Grouping Columns in an HTML Table using Angular 4

I'm currently faced with the task of retrieving flat data from an API and presenting it in an HTML table using Angular 4. I'm a bit unsure about how to iterate over the data, possibly using a for-each loop. I have attempted to utilize ngFor but I ...

It is not possible to access an object's properties using bracket notation when the index is a variable

Is there a way to convert the JavaScript code below into TypeScript? function getProperties(obj) { for (let key in obj) { if (obj.hasOwnProperty(key)) { console.log(obj[key]); } } } I've been trying to find a solution but it seems t ...

I am looking for an Angular Observable that only returns a single value without any initial value

Is there a way to create an Observable-like object that calls a webservice only once and shares the result with all subscribers, whether they subscribe before or after the call? Using a Subject would provide the result to subscribers who subscribed before ...

A guide on automatically focusing on a Material UI Formik form TextField using React and TypeScript

I'm attempting to automatically focus my textField, but the 'autoFocus' attribute only seems to work after I submit the form and add a value. If no values are added (i.e. when opening the miui modal for the first time), the autoFocus does no ...

Is there a way to solely expand the type declarations from a separate class?

Imagine we have two distinct classes X and Y with 77 property-type declarations in common, but their methods, including constructors, are different: class X { public prop1: number; public prop2: string; //... public prop77: "hello"; constructor(){ th ...

Tips for maintaining knowledge after redirecting to a new page

Building an app using Ionic 4 where I need to display vouchers from a database as images. Each image should act as a link to a details page showing more information about that specific voucher. However, I am struggling to figure out how to keep track of th ...

Struggling with TypeScript compilation in a Vue.js project? Encounter error code TS2352

Here is my code snippet from window.ts import Vue from 'vue' interface BrowserWindow extends Window { app: Vue } const browserWindow = window as BrowserWindow export default browserWindow Encountering a compilation error Error message: TS2 ...

The error message "props.text is undefined in React Native" indicates that there is an issue with accessing the property text within

//**// import { StatusBar } from 'expo-status-bar'; import {StyleSheet, Text, View, Button, TextInput, ScrollView, FlatList} from 'react-native'; import {useState} from "react"; import GoalItem from "./components/GoalItem"; export defau ...

What is the best way to determine the type of `rootReducer`?

My project is set up with a combination of React, Redux, Immutable.js, and TypeScript. As I worked on implementing it, I made an effort to declare types wherever possible which led me to discover an interesting issue. A code example illustrating the proble ...