---
id: pushed-set
title: pushed-set
hide_title: true
sidebar_label: pushed-set
---

# `pushedSet(valueOrCallback)`
**`create.pushedSet`**
**`create(actionType).pushedSet`**
*Appropriate leaf type: object*

Returns an (action) object that the [reduxLeaves](../README.md) reducer uses to non-mutatively update the leaf's state at an auto-generated key (that orders chronologically after previous keys) with `value`.

(This is inspired by the [Firebase Real-Time Database .push](https://firebase.google.com/docs/database/web/lists-of-data#append_to_a_list_of_data) and uses [their method for auto-generating keys](https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html).)

## Parameters
- `valueOrCallback` *(any)*:
  - the value to set; or
  - a callback function that uses the autogenerated key and returns the value to set

## Returns
`action` *(object)*: an object to dispatch to the store

## Example
```js
import { createStore } from 'redux'
import reduxLeaves from 'reduxLeaves'

const initialState = {
  foo: {},
  bar: {}
}

const [reducer, actions] = reduxLeaves(initialState)
const store = createStore(reducer)
```

### Passing a value
```js
const pushedSetInFoo = actions.foo.create.pushedSet
store.dispatch(pushedSetInFoo('my first item'))
store.dispatch(pushedSetInFoo('my second item'))
console.log(store.getState().foo)
/*
  will look something like:
  {
      5bzqUkZnXzQIpIbg5dq8pzIrFVT2: 'my first item',
      B4y3IRRyR6hbFlu7s1HheCPPv5x1: 'my second item'
    }
*/

// Auto-generated keys guarantee expected order iteration
const orderedValues = Object.values(store.getState().foo)
console.log(orderedValues) // ['my first item', 'my second item']
```

### Passing a callback
```js
const pushedSetInBar = actions.foo.create.pushedSet
store.dispatch(pushedSetInBar(autoGeneratedKey => ({ id: autogeneratedKey, text: 'my first item' })))
console.log(store.getState().bar)
/*
  will look something like:
  {
    5bzqUkZnXzQIpIbg5dq8pzIrFVT2: {
      id: '5bzqUkZnXzQIpIbg5dq8pzIrFVT2',
      text: 'my first item'
    }
*/

```