B
B
Breezy
Search…
Utility

API

getIn

1
import {getIn} from '@thoughtbot/superglue'
Copied!
Arguments
Type
Notes
obj
Object
Typically the redux state.
path
String
A keypath to the node in your state, posts.post_id=1.comment.0.body
Traverses to the node using a keypath. For example, given a page that looks like this:
1
'/posts': {
2
data: {
3
posts: [
4
{
5
post_id: 1
6
title: 'hello world'
7
comments: [
8
{
9
comment_id: 1,
10
body: 'Here's a comment
11
}
12
]
13
}
14
]
15
}
16
}
Copied!
To reach the comment body you could do this:
1
getIn(state, '/posts.data.posts.0.comment.0.body')
Copied!
or find first by its attribute and value
1
getIn(state, '/posts.data.post_id=0.comment.0.body')
Copied!
The above would find the first occurrence where post_id=1 before continuing traversing.
Last modified 16d ago
Copy link
Contents
API
getIn