npm install
npm start
This will open Chrome and launch your application
(You are running reason-scripts which has bindings on react-scripts)
Notice that each file translates to a Module in Reason.
So if you declare a bar
variable in foo.re
, you will be able to access it, in another file, like so: Foo.bar
.
We assigned ReasonReact.stringToElement
to ste
, so you can use Utils.ste
easily in other files. (Less verbose)
We also have a helper function to transform an event from an input text to the value it contains. (You will need it at the end of the HackJam)
This is our mock database we will use. It contains the data and the types of our database.
By fixing this bug, you will understand how JSX calls a function under the hood.
When, in the index.re
, we call <App route/>
this is actually calling the make
function of the app.re
file.
ReasonML won't let you have runtime errors. To do so, everything should be typed. Even simple text in a JSX tag.
Define the kind of actions this component has. (Only fix the first TODO in this file!) In Reason, we define them with Variants https://reasonml.github.io/guide/language/variant. e.g.:
type actions =
| Click
| Send(string)
| Send(string, int);
Note: You will have to use the Database.book
type here.
Display all books by mapping on each book and calling the book
function, which displays a single book.
The book
function misses some text!
To display a list of books,
you need to transform your list to an array (Array docs)[https://reasonml.github.io/api/Array.html]
and then translate that array in a ReasonReact component (ReasonReact render docs)[https://reasonml.github.io/reason-react/docs/en/render.html]
You should also fix the href
in the book
function.
If you click on a book in the browser, you won't be redirected to the book detail because you're still missing the implementation in app.re. Let's do that in the next step.
Add the navbar Component (Notice how easy imports are)
You notice that the switch
on the route
only handles the DashBoardRoute
.
Let's add the BookDetailsRoute
. For now don't implement the save method. You can mock it like this: save=(fun book => ())
You should now be able to go to the book details.
Let's now add the ManageBooksRoute
. Again, mock the add
and delete
functions for now.
Let's now fix the reducer (reducer docs)[https://reasonml.github.io/reason-react/docs/en/state-actions-reducer.html] First implement the delete, then update and add.
Add the BookSearch component
Transform in reducerComponent:
Fix all reducer functions Fix input element to update title Fix add button
If the bookSearch component works, you'll see there's a bug:
didUpdate
lifeCycle function. When the previous property id changed, send an action to add this new book to the component state.
To do so, you'll need retainedProps
:
Transform your component in reducerComponentWithRetainedProps
: add retained property and didUpdate
lifecycle.Reason: https://reasonml.github.io/
ReasonReact: https://reasonml.github.io/reason-react/
(Should not be necessary)
BuckleScript: https://bucklescript.github.io/bucklescript/Manual.html