score:193
react navigation 3.0 has a number of breaking changes including an explicit app container required for the root navigator.
in the past, any navigator could act as the navigation container at the top-level of your app because they were all wrapped in “navigation containers”. the navigation container, now known as an app container, is a higher-order-component that maintains the navigation state of your app and handles interacting with the outside world to turn linking events into navigation actions and so on.
in v2 and earlier, the containers in react navigation are automatically provided by the create*navigator functions. as of v3, you are required to use the container directly. in v3 we also renamed createnavigationcontainer to createappcontainer.
also please note that if you are now using v4, navigators have been moved to a separate repo. you'll now need to install and import from 'react-navigation-stack'
. for example import { createstacknavigator } from 'react-navigation-stack'
the solution below is for v3.
import {
createstacknavigator,
createappcontainer
} from 'react-navigation';
const mainnavigator = createstacknavigator({...});
const app = createappcontainer(mainnavigator);
a more comprehensive code example:
import {
createstacknavigator,
createappcontainer
} from 'react-navigation';
import login from './view/login.js'
import signup from './view/signup.js'
const rootstack = createstacknavigator({
home: {
screen: login
},
signup: {
screen: signup
}
});
const app = createappcontainer(rootstack);
export default app;
score:-2
i been struggling from past few days .well might be you too been struggling to solve if and if you have deleted the react-navigation from package.json and installed using npm please check your backup project and see the navigation version and try to add the same and remove node-modules and do npm install. hope its works.
good luck breaking your head with react-native :-)
score:2
import react, { component } from 'react';
import { createstacknavigator, createappcontainer } from 'react-navigation';
import home from './home';
import details from './details';
const root = createstacknavigator({
home: {
screen: home,
},
details: {
screen: details,
},
});
const container = createappcontainer(root);
export default container;
in your app.js file reference it with </container>
score:2
i had the code at the bottom
export default class app extends react.component {
render() {
return (
<view >
<simpleapp style={{ width: dimensions.get("window").width }} />
</view>
);
}
}
i simply replaced it with and it worked like a charm. definitely, it's because updates in react-navigation library:
const app = createappcontainer(simpleapp);
export default app;
also, i included createappcontainer library into react-navigation at the top as well.
score:2
this one is to create a bottom navigator with two tabs:
import {createbottomtabnavigator, createappcontainer} from 'react-navigation';
export class home extends component{
//...
}
export class settings extends component{
//...
}
const navig = createbottomtabnavigator({
home: home,
settings: settings
});
const app = createappcontainer(navig);
export default app;
score:3
const appnavigator = createstacknavigator({
home: { screen: home },
friends: { screen: friends },
});
simple i did
const app = createappcontainer(appnavigator);
export default app;
instead of
export default appnavigator;
score:6
here's another way
import react, {component} from 'react';
import { stylesheet, text, view } from 'react-native';
import { createstacknavigator,createappcontainer } from 'react-navigation';
import login from './view/login.js'
import signup from './view/signup.js'
const rootstack = createstacknavigator(
{
home: {
screen: login
},
signup: {
screen: signup
}
},
{
initialroutename: 'home'
}
);
class app extends react.component {
render() {
return <rootstack />;
}
}
export default createappcontainer(rootstack);
score:7
i wasted my 2.5 hours to got this solution after many google searches...hope this will work.
just import this two:
import { createstacknavigator } from "react-navigation-stack";
import { createappcontainer } from "react-navigation";
and make a little change to your code like this:
create const above the class
const appnavigator = createappcontainer(rootstack);
and finally call that const in the class instead of <rootstack/>
<appnavigator />
thankx!
score:11
create a new file screencontainer.js (you can choose the name). then in the screencontainer file add:
import react, { component } from 'react';
import { createstacknavigator, createappcontainer } from 'react-navigation';
import mainscreen from './mainscreen';
import aboutscreen from './aboutscreen';
const navigationstack = createstacknavigator({
main: {
screen: mainscreen,
},
about: {
screen: aboutscreen,
},
});
const container = createappcontainer(navigationstack);
export default container;
then at your app.js file:
import container from './screencontainer';
class app extends component {
render() {
return (
<container />
);
}
}
score:26
@tom dickson something like this:
import react, { component } from 'react';
import { createstacknavigator, createappcontainer } from 'react-navigation';
import screenone from './screenone';
import screentwo from './screentwo';
const navstack = createstacknavigator({
screenone: {
screen: screenone,
},
screentwo: {
screen: screentwo,
},
});
const app = createappcontainer(navstack);
export default app;
then reference it with
<app />
Source: stackoverflow.com
Related Query
- Invariant Violation: The navigation prop is missing for this navigator
- Invariant Violation: The navigation prop is missing for this navigator. In react-navigation v3 and v4 you must set up your app container directly
- Warning: Unknown prop `onTouchTap` on <div> tag. Remove this prop from the element. For details,
- Where am I missing a key prop here? I'm generating uuids for TableCell keys and I'm using row.id for the row keys
- Uncaught Error: Invariant Violation: findComponentRoot(..., ...$110): Unable to find element. This probably means the DOM was unexpectedly mutated
- eslint: Missing "key" prop for element in iterator (react/jsx-key)
- Error when creating new object from existing one using `...`: In this environment the sources for assign MUST be an object
- Missing "key" prop for element. (ReactJS and TypeScript)
- ReactJS - Unknown prop `activeClassName` on <a> tag. Remove this prop from the element
- React Native Navigation Error: The action navigate with payload {"name": 192.168.100.189:19000", "params":{}} was not handled by any navigator
- What prop type should I check for requiring the source?
- React-Style, Webpack, React - Uncaught Error: Invariant Violation: The `style` prop
- Get the current active screen route of the tab navigator in react navigation
- Observed this Error: Material-UI: The `anchorEl` prop provided to the component is invalid
- Invariant Violation in React Render OR the proper way to iterate and return in React
- bind(): You are binding a component method to the component. React does this for you automatically?
- React warns about passed prop with value null, where the PropType for the prop is not required
- React: Invalid value for prop `savehere` on <div> tag. Either remove it from the element, or pass a string or number value to keep it in the DOM
- Warning: Unknown prop on <> tag. Remove this prop from the element
- Is this React prop passing pattern bad for memory?
- Invariant Violation: Query(...): Nothing was returned from render. This usually means a return statement is missing
- Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons
- How to handle the navigation for the Button click in ReactJS?
- Failed propType: The prop `id` is required to make `Dropdown` accessible for users of assistive technologies such as screen readers
- i18next warn or lint on missing key for a language (not the fallbackLng)
- Why do I get a warning that says " each child in a list should have a unique key prop" but I already have a unique key prop for the child component
- I can't find the matching TypeScript type for `displayName` as a prop of `type`
- React esLint error: Missing "key" prop for element in array
- How to locate react-leaflet map to user's current position and get the borders for this map?
- React Navigation - navigate and set history for the back button
More Query from same tag
- oidc-client or oidc-token-manager in react+flux application
- Calling setState in callback of setState generate a weird bug that prevents input's value to be updated by onChange
- Why is using setState inside componentDidUpdate seen as a bad practice in React?
- Unhandled Rejection (TypeError): Cannot read property 'refetch' of undefined - GraphQL
- Check if State is empty when transferring to a new page
- Sending data from a form in React to DyanmoDB via AWS Lambda with Node
- Action on window resize in React
- How to call this get api with sending the body using axios?
- How to load response data using axios in react?
- React render is missing semicolon
- Content of Reactstrap Modal is not visible to jest mount
- Read audio file in a POST request to Flask API
- object in redux state disappearing when another action is triggered
- ReactJS - How detect if an element is the nth _ first _ or last child of its parent in ReactJS?
- React how to send object to onClick event
- Jest on React, local state with useState
- Change the height of the row instead of the column width
- Apply same styling on multiple elements in component
- validating deep fields in redux-from
- React change placeholder text color using React inline styling
- React Transition Group - Magnetic slider (change direction not working correctly)
- Using multiple Webpack loaders to transform SVGs into React components
- How do I route in react word web add-in?
- ReactJs - state is rendered properly but inside method, shows wrong value
- Keep state when refreshing
- React Router Link changes URL but doesn't render Component - Rest Countries API
- Routing with Django and React
- React | How to remove prevent.default from state update
- react TextField material UI value
- How to add required attribute on specific table row index in react js?