Skip to Main Content
React w działaniu
book

React w działaniu

by Stoyan Stefanov
April 2017
Intermediate to advanced content levelIntermediate to advanced
240 pages
5h 35m
Polish
Helion
Content preview from React w działaniu

Rozdział 2. Życie komponentu

Wiesz już, jak używać gotowych komponentów DOM, dlatego możesz się zabrać za tworzenie własnych.

Absolutne minimum

API służące do utworzenia nowego komponentu wygląda następująco:

var MyComponent = React.createClass({
   /* specyfikacje */
});

Napis „specyfikacje” reprezentuje obiekt JavaScriptu, który zawiera jedną wymaganą metodę o nazwie render() oraz kilka opcjonalnych metod i właściwości. Najprostszy możliwy przykład wygląda tak:

var Component = React.createClass({
   render: function() {
      return React.DOM.span(null, "Jestem zupełnie niestandardowy");
   }
});

Jak widać, jedyną rzeczą, którą musisz zrobić, jest zaimplementowanie metody render(). Ta metoda musi zwracać komponent Reacta, dlatego w powyższym ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pro React

Pro React

Cássio de Sousa Antonio
React od podstaw

React od podstaw

Alex Banks Eve Porcello

Publisher Resources

ISBN: 9781098125332