Skip to content

Commit b285048

Browse files
justin808claude
andcommitted
Fix require order and improve React component performance
Redux Generator: - Move GeneratorMessages require to top of file to fix load order - Fix detect_package_manager calls to use proper module method - Remove duplicate require statement in add_redux_specific_messages React Component Improvements: - Use modern JSX transform (remove React import) - Add useMemo to prevent store recreation on re-renders - Use type-only imports for better tree-shaking - Switch from React.FC to FC import Addresses additional code review feedback for performance and correctness. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent c721d4e commit b285048

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

lib/generators/react_on_rails/react_with_redux_generator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require "rails/generators"
44
require_relative "generator_helper"
5+
require_relative "generator_messages"
56

67
module ReactOnRails
78
module Generators
@@ -82,7 +83,7 @@ def add_redux_npm_dependencies
8283
# Fallback to package manager detection if GeneratorHelper fails
8384
return if success
8485

85-
package_manager = detect_package_manager
86+
package_manager = GeneratorMessages.detect_package_manager
8687
return unless package_manager
8788

8889
install_packages_with_fallback(regular_packages, dev: false, package_manager: package_manager)
@@ -126,7 +127,6 @@ def build_install_command(package_manager, dev, packages_str)
126127

127128
def add_redux_specific_messages
128129
# Override the generic messages with Redux-specific instructions
129-
require_relative "generator_messages"
130130
GeneratorMessages.output.clear
131131
GeneratorMessages.add_info(
132132
GeneratorMessages.helpful_message_after_installation(component_name: "HelloWorldApp")
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React from 'react';
1+
import { useMemo, type FC } from 'react';
22
import { Provider } from 'react-redux';
33

4-
import configureStore, { RailsProps } from '../store/helloWorldStore';
4+
import configureStore, { type RailsProps } from '../store/helloWorldStore';
55
import HelloWorldContainer from '../containers/HelloWorldContainer';
66

77
// Props interface matches what Rails will pass from the controller
@@ -10,10 +10,14 @@ interface HelloWorldAppProps extends RailsProps {}
1010
// See documentation for https://github.com/reactjs/react-redux.
1111
// This is how you get props from the Rails view into the redux store.
1212
// This code here binds your smart component to the redux store.
13-
const HelloWorldApp: React.FC<HelloWorldAppProps> = (props) => (
14-
<Provider store={configureStore(props)}>
15-
<HelloWorldContainer />
16-
</Provider>
17-
);
13+
const HelloWorldApp: FC<HelloWorldAppProps> = (props) => {
14+
const store = useMemo(() => configureStore(props), [props]);
15+
16+
return (
17+
<Provider store={store}>
18+
<HelloWorldContainer />
19+
</Provider>
20+
);
21+
};
1822

1923
export default HelloWorldApp;

0 commit comments

Comments
 (0)