Themes in React Native – Adam Bene – Medium

Themes in React Native  #reactnative #javascript #react #reactjs #reactjs

  • Themes in React Nativetheme provider and UI elementsWhen developing a large scale app it is a good idea to build our own UI components.
  • The styles should be factored out to be DRY.ContextReact context is a suitable tool for dependency injection.
  • Let’s inject our theme.ThemeProvider theme={lightTheme} ButtonTap param is props, 2nd is context.contextTypes has to be defined in order to receive properties in context.
  • Otherwise context will be empty.const Button = ({ text }, { theme }) = ( TouchableHighlight Text style={{ theme.color }}{text}/Text = { theme: PropTypes.shape({ color: PropTypes.string })}ThemeProviderThe return value of getChildContext() will be propagated to its children down the component tree as context.childContextTypes property is needed to defined.class ThemeProvider extends React.Component { getChildContext() { return { theme: this.props.theme } } render() { return this.props.children = { theme: PropTypes.shape({ color: PropTypes.string })}Change ThemesThemes can be changed through props.
  • The example below toggles two themes in the state.light theme by defaultdark theme with smaller border radius, paddings, margins and fontsWorking ExampleYou can try out a working example both on iOS and Android after setting up development environment.react-native run-iosreact-native run-androidSee Also

When developing a large scale app it is a good idea to build our own UI components. The styles should be factored out to be DRY. React context is a suitable tool for dependency injection. Similar to…
Continue reading “Themes in React Native – Adam Bene – Medium”

How to use React’s Provider Pattern

  • Therefore you could use React’s context to give every component access to the colored theme.
  • That way every component that needs to be styled according to the colored theme could get the necessary information from React’s context object.
  • You have the Provider component that makes properties accessible in React’s context and components that consume the context.
  • This Provider component uses React’s context to pass down the state implicitly.
  • You provide the state to your component as props, the component wraps it into React’s context and all child components can access the state by using a higher order component such as from the react-redux library.

This article gives you a walkthrough for React’s provider pattern. After reading it, you should be able to implement…
Continue reading “How to use React’s Provider Pattern”

The Provider and Higher-Order Component patterns with React

The provider and higher-order component patterns with #ReactJS:

  • The best way to create a reusable functionality is a Higher-Order Component.
  • const React, { Component, PropTypes } from “react” const theme = (ComponentToWrap) => { return class ThemeComponent extends Component { // let’s define what’s needed from the `context` static contextTypes = { theme: PropTypes.object.isRequired, } render() { const { theme } = this.context // what we do is basically rendering `ComponentToWrap` // with an added `theme` prop, like a hook return ( ) } } } export default theme
  • import React, { Component, PropTypes, Children } from “react” class ThemeProvider extends Component { static propTypes = { theme: PropTypes.object.isRequired, } // you must specify what you’re adding to the context static childContextTypes = { theme: PropTypes.object.isRequired, } getChildContext() { const { theme } = this.props return { theme } } render() { // `Children.only` enables us not to add a

    for nothing return Children.only(this.props.children) } } export default ThemeProvider

  • With the Provider , you are now able to pass the theme to any component who requires it.
  • Now that our theme is added to the context , we need a simple way for the components to grab it.

Lots of React libraries need to make their data pass through all your component tree. For instance, Redux needs to pass its store and React Router needs to pass the current location. This could…
Continue reading “The Provider and Higher-Order Component patterns with React”

React Native Israel (Tel Aviv-Yafo)

Great talk by @PoTpOcKey today at React Native Israel #ReactNative

  • Yoni G. RSVPed Yes for React Native Sunday Hub
  • We’re hosting an open house for React Native developers every Sunday until lunchtime.
  • Or B. commented on Real World Apps with React Native
  • The Meetup repeats every week on Sunday
  • Come grab a cup of coffee and some snacks and do some React Native with us!

Read the full article, click here.


@jondot: “Great talk by @PoTpOcKey today at React Native Israel #ReactNative”


This is a group for people that are interested with React (Facebook’s React), and its Native variant called React Native. React Native was opensourced by Facebook a short while ago and it promises to


React Native Israel (Tel Aviv-Yafo)

More Ways to Extend React Storybook — KADIRA VOICE

We've introduce a new extension API for #reactjs storybook:

  • Today, we are introducing an extension API with which you can write extensions to React Storybook.
  • With addons you can add new functionalities to React Storybook.
  • We started to look for new ways to extend React Storybook while maintaining its stability.
  • You can also share extensions you’ve built and use extensions created by others .
  • You can use the Storybook UI to display anything you want.

Read the full article, click here.


@kadirahq: “We’ve introduce a new extension API for #reactjs storybook:”


We wanted React Storybook to be stable and customizable from day one. This came with a price: contributing to React Storybook was harder…


More Ways to Extend React Storybook — KADIRA VOICE