Skip to content

CoffeeScript React component generator is fixed #768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/generators/react/component_generator.rb
Original file line number Diff line number Diff line change
@@ -129,14 +129,18 @@ def component_name

def file_header
if webpacker?
%|var React = require("react")\n|
if options[:coffee]
%|import React from 'react'\nimport PropTypes from 'prop-types'\n|
else
%|var React = require("react")\n|
end
else
''
end
end

def file_footer
if webpacker?
if webpacker? && !options[:coffee]
%|module.exports = #{component_name}|
else
''
4 changes: 3 additions & 1 deletion lib/generators/templates/component.js.jsx.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class @<%= component_name %> extends React.Component
<%= file_header %>
export default class @<%= component_name %> extends React.Component
<% if attributes.size > 0 -%>
@propTypes =
<% attributes.each do |attribute| -%>
@@ -16,3 +17,4 @@ class @<%= component_name %> extends React.Component
<% else -%>
`<div />`
<% end -%>
<%= file_footer %>