You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
React elements are the building blocks of React applications. One might confuse elements with a more widely known concept of "components". An element describes what you want to see on the screen. React elements are immutable.
React components are small, reusable pieces of code that return a React element to be rendered to the page. The simplest version of React component is a plain JavaScript function that returns a React element:
Components can be broken down into distinct pieces of functionality and used within other components. Components can return other components, arrays, strings and numbers. A good rule of thumb is that if a part of your UI is used several times (Button, Panel, Avatar), or is complex enough on its own (App, FeedStory, Comment), it is a good candidate to be a reusable component. Component names should also always start with a capital letter (`<Wrapper/>`**not**`<wrapper/>`). See [this documentation](/docs/components-and-props.html#rendering-a-component) for more information on rendering components.
@@ -120,47 +120,47 @@ class Welcome extends React.Component {
120
120
121
121
### [`state`, vagy helyi ĂĄllapot](/docs/state-and-lifecycle.html#adding-local-state-to-a-class) {#state}
122
122
123
-
A component needs `state` when some data associated with it changes over time. For example, a `Checkbox`component might need `isChecked`in its state, and a`NewsFeed`component might want to keep track of `fetchedPosts` in its state.
The most important difference between `state`and `props`is that `props`are passed from a parent component, but `state` is managed by the component itself. A component cannot change its`props`, but it can change its `state`.
For each particular piece of changing data, there should be just one component that "owns" it in its state. Don't try to synchronize states of two different components. Instead, [lift it up](/docs/lifting-state-up.html)to their closest shared ancestor, and pass it down as props to both of them.
Lifecycle methods are custom functionality that gets executed during the different phases of a component. There are methods available when the component gets created and inserted into the DOM ([mounting](/docs/react-component.html#mounting)), when the component updates, and when the component gets unmounted or removed from the DOM.
An input form element whose value is controlled by React is called a *controlled component*. When a user enters data into a controlled component a change event handler is triggered and your code decides whether the input is valid (by re-rendering with the updated value). If you do not re-render then the form element will remain unchanged.
An *uncontrolled component* works like form elements do outside of React. When a user inputs data into a form field (an input box, dropdown, etc) the updated information is reflected without React needing to do anything. However, this also means that you can't force the field to have a certain value.
In most cases you should use controlled components.
141
+
A legtöbb esetben próbålj kontrollålt komponenseket hasznålni.
142
142
143
143
## [Kulcsok](/docs/lists-and-keys.html) {#keys}
144
144
145
-
A "key" is a special string attribute you need to include when creating arrays of elements. Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside an array to give the elements a stable identity.
Keys only need to be unique among sibling elements in the same array. They don't need to be unique across the whole application or even a single component.
Don't pass something like `Math.random()`to keys. It is important that keys have a "stable identity" across re-renders so that React can determine when items are added, removed, or re-ordered. Ideally, keys should correspond to unique and stable identifiers coming from your data, such as`post.id`.
React supports a special attribute that you can attach to any component. The`ref`attribute can be an object created by [`React.createRef()`function](/docs/react-api.html#reactcreateref)or a callback function, or a string (in legacy API). When the`ref`attribute is a callback function, the function receives the underlying DOM element or class instance (depending on the type of element) as its argument. This allows you to have direct access to the DOM element or component instance.
Use refs sparingly. If you find yourself often using refs to "make things happen" in your app, consider getting more familiar with [top-down data flow](/docs/lifting-state-up.html).
When a component's props or state change, React decides whether an actual DOM update is necessary by comparing the newly returned element with the previously rendered one. When they are not equal, React will update the DOM. This process is called "reconciliation".
0 commit comments