scrimba
Frontend Career Path
React basics
Notes & Tenzies
Notes App: Note summary title
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Notes App: Note summary title
AboutCommentsNotes
Notes App: Note summary title
Expand for more info
components
Sidebar.js
run
preview
console
import React from "react"

export default function Sidebar(props) {
/**
* Challenge: Try to figure out a way to display only the
* first line of note.body as the note summary in the
* sidebar.
*
* Hint 1: note.body has "invisible" newline characters
* in the text every time there's a new line shown. E.g.
* the text in Note 1 is:
* "# Note summary\n\nBeginning of the note"
*
* Hint 2: See if you can split the string into an array
* using the "\n" newline character as the divider
*/

const noteElements = props.notes.map((note, index) => (
<div key={note.id}>
<div

className={`title ${
note.id === props.currentNote.id ? "selected-note" : ""
}`}
onClick={() => props.setCurrentNoteId(note.id)}
>
<h4 className="text-snippet">Note {index + 1}</h4>
</div>
</div>
))

return (
<section className="pane sidebar">
<div className="sidebar--header">
<h3>Notes</h3>
<button className="new-note" onClick={props.newNote}>+</button>
</div>
{noteElements}
</section>
)
}
Console
/index.html
-4:51