Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Add context support #134

Open
Open
@sollycatprint

Description

@sollycatprint

From @wied03 on March 25, 2016 21:15

In react-opal, you can use the React context feature, like this. I can probably do a PR for this.

class ParentComponent
  include React::Component

  # Simply supply the Ruby/Opal type that :foo will be and react-opal will map that to a React PropType automatically
  provide_context(:foo, Fixnum) { params[:foo_value] }

  def render
    present ChildComponent
  end
end

class ChildComponent
  include React::Component

  consume_context(:foo, Fixnum)

  def render
    # will render the :foo_value prop passed into ParentComponent
    div { "foo is #{self.context[:foo]}" } 
  end
end

Copied from original issue: zetachang/react.rb#134

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions