Skip to content

No way to use wrapperComponent: false with AnimatedSwitch #83

Open
@jvgomg

Description

@jvgomg

I have a use case where I need fine control over styles – specifically I need to add more styles to the element with the tweening styles. { wrapperComponent: false } seemed like the perfect option as it uses cloneElement and injects the styles.

However it turns out there is noway to consume the injected style prop (at least with AnimatedSwitch) – cloned element is actually an internal provided Switch component.

Is there something I am missing?

I came up with a work around I thought I would share using recompose and React context.

const WithStyleContext = withContext({ style: PropTypes.object }, ({ style }) => ({ style }))(({ children }) => children)

const StyleWrapper = getContext({ style: PropTypes.object })('div')

<AnimatedSwitch
  wrapperComponent={WithStyleContext}
  children={[
    <Route 
      children={() =>
        <StyleWrapper children="Hello world!" />
      }
    />
  ]}
/>

Is there a way to provide the style prop without needing to use context?

Thanks for the awesome library! :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions