• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Code refactoring in React component

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to React and referring to code in this editor

https://stackblitz.com/edit/react-ts-gsdc4g

which works fine. Pasting the same code below:

 


Since the code is growing fast, I would like to move `private initGrid = () => {}` and `private initGrid2 = () => {}` function related code inside two files viz.`firstTab.tsx` and `secondTab.tsx` respectively. Here is the new editor code with two files:

https://stackblitz.com/edit/react-ts-yheoba


I'm hoping this is the best thing to do and wondering how should I move two functions in two files and then call those two functions inside index.tsx? Because, the two files I created are more like a separate components to me and if I've to create a new component, I would also have to define render method?


 
 
Rancher
Posts: 506
6
IntelliJ IDE Spring Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems like those functions just return some hard coded data. I wouldn't really say those really deserve to be separated.  Actually they do pretty much the same thing so if you do move them out it seems like it would make more sense to move them out together.
 
Jack Tauson
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Al Hobbs wrote:It seems like those functions just return some hard coded data. I wouldn't really say those really deserve to be separated.  Actually they do pretty much the same thing so if you do move them out it seems like it would make more sense to move them out together.



Thanks.What part can be moved out? I am kind of confused how things are going to be separated if I want to do that.
 
grapes are vegan food pellets. Eat this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!