Hello, I am stuck on the new CopyCat project as part of an update to the React course.
https://www.codecademy.com/paths/web-development/tracks/front-end-applications-with-react/modules/react-102-advanced-react-u/projects/copycat
I have split the code into presentational and container components, and by the end of step 4 the app should render, but it doesn’t. Perhaps I’ve gone wrong somewhere when passing props? Any help would be appreciated! Here is my code:
CopyCat.js
import React from 'react';
const images = {
copycat: 'https://content.codecademy.com/courses/React/react_photo_copycat.png',
quietcat: 'https://content.codecademy.com/courses/React/react_photo_quietcat.png'
};
class CopyCat extends React.Component {
render() {
return (
<div>
<h1>Copy Cat</h1>
<img alt='cat'
src={this.props.copying ? images.copycat : images.quietcat}
onClick={this.props.toggleTape}
/>
</div>
);
};
}
export default CopyCat;
CopyCatContainer.js
import React from 'react';
import ReactDOM from 'react-dom';
import CopyCat from '../components/CopyCat';
class CopyCatContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
copying: true
};
this.toggleTape = this.toggleTape.bind(this);
}
toggleTape() {
this.setState({ copying: !this.state.copying })
}
render() {
return <CopyCat copying={this.state.copying} toggleTape={this.toggleTape}/>
};
}
ReactDOM.render(<CopyCatContainer />, document.getElementById('app'));
1 Like
I’ve hit the same wall, but apart from a semi-colon missing from this.setState statement I couldn’t find the reason for no render.
My container:
import React from 'react';
import ReactDOM from 'react-dom';
import { CopyCat } from '../components/CopyCat';
class CopyCatContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
copying: true,
input: '';
name: '';
};
this.toggleTape = this.toggleTape.bind(this);
this.handleChange = this.handleChange.bind(this);
}
toggleTape() {
this.setState({ copying: !this.state.copying });
}
handleChange(event) {
this.setState({input: event.target.value});
}
render() {
return <CopyCat name={this.state.name} copying={this.state.copying} toggle={this.toggleTape} value={this.state.input} {onChange={this.handleChange}/>;
}
}
ReactDOM.render(<CopyCatContainer />, document.getElementById('app'));
My component…
import React from 'react';
import {styles} from '../styles';
const images = {
copycat: 'https://content.codecademy.com/courses/React/react_photo_copycat.png',
quietcat: 'https://content.codecademy.com/courses/React/react_photo_quietcat.png'
};
export class CopyCat extends React.Component {
render() {
return (
<div style={styles.divStyles}>
<h1 style="marginBottom: 80">Copy Cat {this.props.name ? this.props.name : 'Tom'}</h1>
<input type="text" defaultValue={this.props.value} onChange={this.props.onChange}/>
<img style={styles.imgStyles} alt='cat'
src={this.props.copying ? images.copycat : images.quietcat} onClick={this.props.toggle} />
<p>{this.props.copying && this.props.value}</p>
</div>
);
}
}
MyComponent.propTypes = {
name: React.PropTypes.string
};
Same Issue for me too. Not Seeing the component render.
import React from 'react';
const images = {
copycat: 'https://content.codecademy.com/courses/React/react_photo_copycat.png',
quietcat: 'https://content.codecademy.com/courses/React/react_photo_quietcat.png'
};
export class CopyCat extends React.Component {
render() {
return (
<div>
<h1>Copy Cat</h1>
<img alt='cat'
src={this.props.copying ? images.copycat : images.quietcat}
onClick={this.props.toggleTape}
/>
</div>
);
};
}
import React from 'react';
import ReactDOM from 'react-dom';
import { CopyCat } from '../components/CopyCat';
class CopyCatContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
copying: true
};
this.toggleTape = this.toggleTape.bind(this);
}
toggleTape() {
this.setState({ copying: !this.state.copying })
}
render() {
return (
<CopyCat copying={this.state.copying} toggleTape={this.toggleTape}/>
)
};
}
ReactDOM.render(
<CopyCatContainer />,
document.getElementById('app'));
atifg
October 1, 2020, 8:30pm
4
Hi There
Why this is not working can someone please check and let us know
CopyCat Project
CopyCat.js
import React from 'react';
import styles from '../styles.js';
const images = {
copycat: 'https://content.codecademy.com/courses/React/react_photo_copycat.png',
quietcat: 'https://content.codecademy.com/courses/React/react_photo_quietcat.png'
};
This file has been truncated. show original
CopyCatContainer.js
import React from 'react';
import ReactDOM from 'react-dom';
import CopyCat from '../components/CopyCat.js'
/* const images = {
copycat: 'https://content.codecademy.com/courses/React/react_photo_copycat.png',
quietcat: 'https://content.codecademy.com/courses/React/react_photo_quietcat.png'
}; */
This file has been truncated. show original
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="/styles.css">
<title>CopyCat</title>
</head>
<body>
<main id="app"></main>
This file has been truncated. show original
There are more than three files. show original
Thanks
1 Like
In your render function of CopyCatContainer, did you try putting the instance of CopyCat in a pair of parentheses for the return?
Example
render() {
return **(**CopyCat copying={this.state.copying} toggleTape={this.toggleTape}/>
**)**};
atifg
October 1, 2020, 9:21pm
6
Yes but not working.
I copied the code from website to my laptop installed the react app their and it worked. somthing wrong with website. Even there is no video for help ==> it says in the help section follow the video if you STUCK
Yea I’ve asked around and haven’t received much guidance on this.
atifg
October 2, 2020, 1:37am
8
Hi
I have just finished the project. Simply use your own system
download the project
then simply install the dependencies (use the the following command in your text editor in my case i have used VSCODE)
Command is “npm install”
CopyCat React Project
Cheers
3 Likes
I believe, you don’t have to use parentheses unless your return contains more than a single line of JSX.
So it looks like a bug in Codecademy’s exercise.
1 Like
Yeah it’s bugged for me as well, hopefully someone from their team will see this thread.
One question, how do you download the project files from the lesson’s page? I don’t see anywhere to download and your github has the finished thing already .
atifg
October 2, 2020, 11:32pm
13
I have used vscode (Code editor) => 1:installed react 2: create-react-app
Then copied the code from codecademy
then completed all the assignment steps.
I did it in rush so i left few unnecessary files there so i can finish the project
Cheers
1 Like
Seriously? So, I’ll try in my computer.
same here! Can this be checked please? I prefer do it from codecademy website not my computer. I don’t have React on work’s computer.
Thanks
In the exercise it says to click run but there isnt a run button.
1 Like
Generous,
Thanks, I’ll compare your work to mine. I also use VS Code.
Gratitude,
Rick
samw12
October 16, 2020, 1:45pm
19
Hi Everyone,
After many hours and with massive thanks to the Stack Overflow community, here is my completed solution! I’m not sure if I’ve got step 12 right, but I thought it might help out. Please feel free to share your feedback
4 Likes
Here is my code and it’s rendering in Codecademy perfectly. This is only through step 4
Hope this helps
CopyCat.js
import React from 'react';
const images = {
copycat: 'https://content.codecademy.com/courses/React/react_photo_copycat.png',
quietcat: 'https://content.codecademy.com/courses/React/react_photo_quietcat.png'
};
class CopyCat extends React.Component {
render() {
const copying = this.props.copying;
const toggleTape = this.props.toggleTape
return (
<div>
<h1>Copy Cat</h1>
<img
alt='cat'
src={copying ? images.copycat : images.quietcat}
onClick={toggleTape}
/>
</div>
);
};
}
export default CopyCat;
Here is the CopyCatContainer.js file code
import React from 'react';
import ReactDOM from 'react-dom';
import CopyCat from '../components/CopyCat.js'
const images = {
copycat: 'https://content.codecademy.com/courses/React/react_photo_copycat.png',
quietcat: 'https://content.codecademy.com/courses/React/react_photo_quietcat.png'
};
export class CopyCatContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
copying: true
};
this.toggleTape = this.toggleTape.bind(this);
}
toggleTape() {
this.setState({copying: !this.state.copying})
}
render() {
const copying = this.state.copying;
const toggleTape = this.toggleTape
return (
<CopyCat
copying={this.state.copying}
toggleTape={this.toggleTape}
/>
);
};
}
ReactDOM.render(<CopyCatContainer/>, document.getElementById('app'));
6 Likes
And for me… In fact, the last couple of lessons from this module had all of the amended code/answers in the editor when I clicked next to get to the next step. I think there must be something wrong with this lesson. I’m going to try to use my own system…
1 Like