REACT 6
1
1
1
1
We use objects to dynamically style components, using JSX brackets.
//remember that style needs double {}
const picture={
url: "https://.../635258.jpg",
width: 100,
height: 100
}
function Imma({pic}){
return (
<img
className= {cubo}
src= {pic.url}
style={{
height: pic.height + "px",
width: pic.width + 30 + "px"
}}
/>
)
}
On the DOM we pass the style object prop to the component.
<div className="row col-10 justify-content-center">
<Imma pic={picture} />
<div>
<button className="btn btn-primary" onClick={rotate}>
Rotate
</button>
</div>
</div>
We install the classnames utility to join JSX classes conditionally.
//First the classname then (:) the condition, we can include default classNames
//we useState() to render the conditions
const [roll, setRoll] = useState(false)
let cubo= cn("p-0", {
"rotola": roll
})
function rotate(){
setRoll((x)=> (!x))
}
//and use the className to toggle the CSS animation
.rotola{
animation: roll 4s;
animation-iteration-count: infinite;
}
@keyframes roll {
100%{
transform: rotate(360deg);
}
}

React-Bootstrap Navbar and Carousel
We need to use flexGrow:0 for the nav elements justify and a custom-fill SVG for the React-bootstrap collapse icon.
We can edit the .carousel-indicators and .carousel-control-prev-icon (SVG) in the CSS.
/*Even if the selectors don't appear in the HTML*/
/*The indicators being the square icons on the bottom of the carousel */
/*We edit the colors with %23hexNumber */
#bootlock .carousel-indicators{
margin-bottom: 0;
}
#bootlock .carousel-control-prev/next-icon {
background-image:
url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23e6d200' viewBox='0 0 8 8'%3E%3Cpath d='M5.25 0l-4 4 4 4 1.5-1.5-2.5-2.5 2.5-2.5-1.5-1.5z'/%3E%3C/svg%3E");
}

1
PreviousREACT 5, useRef() instance methods, React keyframe animations, useRef() scroll, onDrag() and onDrop() React EventsNextReact-Spring-1 useSpring(), config, To() interpolate render, useTransition(), React-use-measure.
Last updated
Was this helpful?