Create React Component#
Generated App Code#
The following code is generated in the file src/App.js
.
It contains a function which is a React component.
A React component is a small view which will render some HTML and can have additional behavior.
The function has a return
statement which contains JSX to render the view.
JSX is inline HTML which will be rendered as HTML in the view.
1import logo from './logo.svg';
2import './App.css';
3
4function App() {
5 return (
6 <div className="App">
7 <header className="App-header">
8 <img src={logo} className="App-logo" alt="logo" />
9 <p>
10 Edit <code>src/App.js</code> and save to reload.
11 </p>
12 <a
13 className="App-link"
14 href="https://reactjs.org"
15 target="_blank"
16 rel="noopener noreferrer"
17 >
18 Learn React
19 </a>
20 </header>
21 </div>
22 );
23}
24
25export default App;
Exercise#
Change the App.js
file to show two FAQ items with the following content:
Question 1: What does the Plone Foundation do?
Answer 1: The mission of the Plone Foundation is to protect and promote Plone. The Foundation provides marketing assistance, awareness, and evangelism assistance to the Plone community. The Foundation also assists with development funding and coordination of funding for large feature implementations. In this way, our role is similar to the role of the Apache Software Foundation and its relationship with the Apache Project.
Question 2: Why does Plone need a Foundation?
Answer 2: Plone has reached critical mass, with enterprise implementations and worldwide usage. The Foundation is able to speak for Plone, and provide strong and consistent advocacy for both the project and the community. The Plone Foundation also helps ensure a level playing field, to preserve what is good about Plone as new participants arrive.
Use an unordered list with an item for each FAQ entry containing an h2
tag for the question, and a p
tag for the answer.
Remove all other boilerplate code including styling.
Extra Information#
If you're unfamiliar with React/ES6, here are some short pointers to the default create-react-app
boilerplate.
JSX is a special format where it seems you are writing html code, but before execution the source is first transformed to valid JavaScript.
The <div>
, <ul>
, <p>
, and other tags in this code are first translated into valid JavaScript code using the function React.CreateElement
.
create-react-app
automatically adds this preprocessing of JSX.
The last line of our App
component is marked as the default export for this JavaScript file.
Check out ES6 module documentation.
Note that React allows you to import and treat images and CSS as direct resources.
The curly braces used for the <img src=>
attribute signal to JSX that what follows is executable JavaScript.