I'm new to react and I don't understand why the title inside the h1 tag gets updated, but the url inside the Image Component doesn't ?
Listing Component
import React, { useState, useEffect, useContext } from 'react';
import Image from './Image';
import Size from '../index';
export default function Listing(props) {
const [title, setTitle] = useState(props.title);
const [url, setUrl] = useState(props.url);
const value = useContext(Size);
return (
<div>
<Image url={url} size={value.size} />
<h1>{title}</h1>
<form>
<input id='URL' type='text' />
<button
onClick={e => {
e.preventDefault();
setUrl(document.getElementById('URL').value);
setTitle(document.getElementById('URL').value);
}}
>
Submit
</button>
</form>
</div>
);
}
My guess so far is that React wont update a child component if a prop changes, but how can I update that manually then ?
Image Component
import React from 'react';
export default class Image extends React.Component {
//console.log(props.size);
constructor(props) {
super(props);
this.url = props.url;
this.size = props.size;
}
render() {
return <img src={this.url} style={{ height: this.size + 'px' }} alt='' />;
}
}```