Skip to content
Closed
Show file tree
Hide file tree
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
Expand Up @@ -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
''
Expand Down
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| -%>
Expand All @@ -16,3 +17,4 @@ class @<%= component_name %> extends React.Component
<% else -%>
`<div />`
<% end -%>
<%= file_footer %>