1.1 KiB
1.1 KiB
Notes
Props
Props stands for properties. A system for passing data from a parent component to a child component. The goal is to customize or configure the child component.
Props are objects so the fields have to be called as methods: props.author
for instance.
Functional components
Used anytime to show simple content to the user. (the card for example -- create JSX pass some props and return it).
Class components
For complex content, respond to user input, network request. Can use the state input.
Class components are not classes in terms of Ruby or Python, they are a Javascript Class. They also must be extended to a subclass (react component). And they must define a render
method that returns some amount of JSX.
State
Rules
- Only usable with class components (not always true)
- state =/= props
State
is a JS object that contains data relevant to a component- Updating
state
on a component causes the component to almost instantly rerender State
must be initialized when a component is createdState
can only be updated with thesetState
function