Created
September 15, 2016 22:34
-
-
Save panw/ef42b2c226d8fa8b30c90ea3702ad211 to your computer and use it in GitHub Desktop.
If a React Component was Written in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Timeline << React::Component { | |
def initialize(props) { | |
super(props) | |
@state = { tweets: [] } | |
} | |
def component_did_mount() { | |
self.fetchTweets(); | |
} | |
def fetch_tweets() { | |
open('/tweets/recent') do |response| | |
self.setState({tweets: response}) | |
end | |
} | |
def render() { | |
# Assumes JSX exist in Ruby | |
return ( | |
<section> | |
<ul> | |
<% @state.tweets.each do |tweet| %> | |
<Tweet data=<% tweet %> /> | |
<% end %> | |
</ul> | |
</section> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment