score:3

Accepted answer

pass a boolean prop for success/warning and use a ternary operator to conditionally set the src attribute.

something like:

const img = ({ success }) => (
  <img
    style={{ width: '48px', height: '48px', position: 'absolute' }}
    src={success ? successicon  : warningicon}
  />
);

score:1

use a ternari in the source:

   const [ stateimage, setstateimage ] =usestate(false);

      src={stateimage ? 'one image' : 'another image'}

Related Query

More Query from same tag