Refract
  • Read Me
  • Introduction
    • Why Refract?
    • Core Concepts
    • Thinking In Refract
    • Alternatives
  • Usage
    • Getting Started
    • Installation
    • Connecting To React
    • Observing React, Preact and Inferno
    • Injecting Dependencies
    • Observing Redux
    • Observing Anything
    • Handling Effects
    • Pushing to Props
    • Rendering Components
    • Handling Errors
    • Testing
  • Recipes
    • Dependency Injection
    • Creating An API Dependency
    • Handling state
    • Replacing Redux Connect
  • Examples
    • Debounced fetch
    • Counter
    • Field validation
    • Redux fetch
    • Routing
    • Typeahead
    • Visit time
  • API
    • compose
    • withEffects
    • toProps, asProps
    • useRefract
    • refractEnhancer (Redux)
  • Glossary
  • Feedback
Powered by GitBook
On this page
  • Packages
  • Arguments
  • Returns
  1. API

toProps, asProps

Packages

toProps and asProps are provided by our React, Inferno or Preact packages - refract-*, refract-inferno-*, refract-preact-*.

Note that by default, props passed to toProps and asProps won't be merged with previous values: to enable this behaviour, you need to set mergeProps to true in withEffects config.

Arguments

Both toProps and asProps take an object of props.

Returns

Similarly to a Redux action creator, they return an object containing type and payload attributes, so it can be recognised by Refract.

export const toProps = props => ({
    type: PROPS_EFFECT,
    payload: {
        replace: false,
        props
    }
})

export const asProps = props => ({
    type: PROPS_EFFECT,
    payload: {
        replace: true,
        props
    }
})
PreviouswithEffectsNextuseRefract

Last updated 6 years ago