DEV Community

Kyle Hoskins
Kyle Hoskins

Posted on

9 2

🙅 Never copy/paste when you’re learning React (or any other library/language)

Learning a new language or library and thinking about copying and pasting that Stack Overflow chunk of code, tutorial example, or "Getting Started" code block?

Think again!

Why not? Let's examine...

The Benefits of "typing it out"

Taking the extra time to type something out rather than copying and pasting it gives you several advantages:

🧠 Memory

The learning period is the most important phase to take the extra time to ensure you're getting in actual practice.

Take a breath, take it slow, and you will be thankful that you actually remember the syntax later. (... and don't worry, your code typing speed will become much faster! 🚀)

🧑‍💻 Interviews

Ctrl+C, Ctrl+P can be a good tool for speed in some cases, but it won't help much when you're expected to quickly code for yourself in a fast-paced, high pressure situation.

Would you copy/paste or type-out the following basics?

npm install --save-dev @testing-library/react
// It's beneficial to know terminal basics 
// like npm, git, etc
Enter fullscreen mode Exit fullscreen mode
test('loads and displays greeting', () => {
  render(<Fetch url="/greeting" />)
  expect(screen.getByText('Load Greeting')).toBeInTheDocument()
})
// Without looking, can you write a complete test spec 
// file from scratch?
Enter fullscreen mode Exit fullscreen mode
import React, { useState } from 'react';
import IconButton from '@mui/material/IconButton';
import SplitRow from 'components/layout/SplitRow';
// Manually typing imports helps understand and remember
// libraries and project structure
Enter fullscreen mode Exit fullscreen mode

♻️ Refactoring/Reuse

Sometimes the ease of copy/paste prevents us from realizing what should be refactored into its own method or component.

You'll quickly become annoyed by typing repetitive code and start enjoying creating re-usable blocks as you code rather than coming back to it later.

✅ Code Quality

When you're writing a new file/code block, it's tempting to copy/paste similar code from somewhere else in your project and make small adjustments.

However, hastily copy/paste/adjusting may leave you with a "hack" or other issues like sub-optimal naming conventions. Additionally, you may have already learned a better way to accomplish the task than in your previous code.

I hope you'll enjoy copying/pasting less and coding more!

P.S. Sometime's screen real estate is an issue, so I use a learning hack of copying and pasting into my file, typing out the same code above the pasted block, then deleting the pasted code

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay