---
id: stack
title: Stack
sidebar_label: Stack
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
## `push()`
Push a screen into the stack and update the display according to the screen options.
#### Parameters
| Name | Required | Type | Description |
| ----------- | -------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| componentId | Yes | string | The componentId of a screen pushed into the stack, or the id of the stack. |
| layout | No | Layout | The layout being pushed into the stack. Any type of layout (except stack) can be pushed into stacks. Typically, Component layout is pushed into stacks but it's possible to push SideMenu or BottomTabs as well. |
#### Example
The most common use case - push a single React component.
```js
Navigation.push(this.props.componentId, {
component: {
name: 'example.PushedScreen'
}
});
```
Options are applied when the screen becomes visible.
```js
Navigation.push(this.props.componentId, {
component: {
name: 'example.PushedScreen',
options: {
topBar: {
title: {
text: 'Pushed screen title'
}
}
}
}
});
```
Any layout type can be pushed. In this example we push a SideMenu layout.
```js
Navigation.push(this.props.componentId, {
sideMenu: {
left: {
component: {
name: 'drawerScreen'
}
},
center: {
component: {
name: 'centerScreen'
}
}
}
});
```
## `pop()`
Pop the top screen from the stack.
#### Parameters
| Name | Required | Type | Description |
| ------------ | -------- | ----------------------------------- | --------------------------------------------------------------------- |
| componentId | Yes | string | The componentId of a screen pushed into the stack, or the stack id. |
| mergeOptions | No | [Options](options-root.mdx) | Options to be merged before popping the screen (optional). |
```js
Navigation.pop(this.props.componentId);
```
## `popToRoot()`
Pop all screens pushed into the stack.
#### Parameters
| Name | Required | Type | Description |
| ------------ | -------- | ------- | --------------------------------------------------------------------- |
| componentId | Yes | string | The componentId of a screen pushed into the stack, or the stack id. |
| mergeOptions | No | [Options](options-root.mdx) | Options to be merged before popping the screen (optional). |
```js
Navigation.popToRoot(this.props.componentId);
```
## `popTo()`
Pop the stack to a given component.
#### Parameters
| Name | Required | Type | Description |
| ------------ | -------- | --------------------- | -------------------------------------------------------- |
| componentId | Yes | string | The destination componentId |
| mergeOptions | No | [Options](options-root.mdx) | Options to be merged before popping the screen (optional). |
```js
Navigation.popTo(componentId);
```
## `setStackRoot()`
Reset the stack to the given layout (accepts multiple children).
#### Parameters
| Name | Required | Type | Description |
| ----------- | -------- | -------------------------------------------------------- | --------------------------------------------------------------------- |
| componentId | Yes | string | The componentId of a screen pushed into the stack, or the stack id. |
| layout | Yes | [layout](layout-layout.mdx) or [layout](layout-layout.mdx)[] | A single Component or array of components. |
#### Example
```js
Navigation.setStackRoot(this.props.componentId, {
component: {
name: 'example.NewRootScreen'
}
});
```
In the example below we reset the stack with two components. The first one will be the root component and the second (`PushedScreen`) will be displayed. Pressing the back button (either hardware or software) will pop it, revealing the root component - `NewRootScreen`.
```js
Navigation.setStackRoot(this.props.componentId, [
{
component: {
name: 'NewRootScreen',
}
},
{
component: {
name: 'PushedScreen',
}
}
]);
```