Skip to content

Commit f8aa1b9

Browse files
committed
separated the tags array
1 parent 72456e2 commit f8aa1b9

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/components/EditProfile.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { Component, useState, useRef, useEffect } from "react";
22
import { Link } from "react-router-dom";
3+
import "../styles/editProfile.sass";
34

45
const EditProfile = (props) => {
56
const [name, setName] = useState("");
@@ -31,8 +32,10 @@ const EditProfile = (props) => {
3132
e.preventDefault();
3233
console.log("hobby is:", hobbyRef.current.value);
3334
let prevHobbies = hobbies;
35+
if(hobbyRef.current.value!= ""){
3436
prevHobbies.push(hobbyRef.current.value);
35-
setHobbies([prevHobbies]);
37+
}
38+
setHobbies([...prevHobbies]);
3639
// let hobs = [...profile.hobbies];
3740
// setProfile((hobs) => [...hobs, hobbyRef.current.value]);
3841
console.log("his hobby is:", hobbies);
@@ -42,8 +45,9 @@ const EditProfile = (props) => {
4245
const addSkills = (e) => {
4346
e.preventDefault();
4447
let prevSkills = skills;
45-
prevSkills.push(skillRef.current.value);
46-
setSkills([prevSkills]);
48+
if(skillRef.current.value!=""){
49+
prevSkills.push(skillRef.current.value);}
50+
setSkills([...prevSkills]);
4751
skillRef.current.value = "";
4852
console.log(EditedProfile)
4953
};
@@ -108,13 +112,9 @@ const EditProfile = (props) => {
108112
</div>
109113
</div>
110114
<div className="form-group">
111-
{hobbies.map((h) => {
112-
return hobbies.length >= 1 ? (
113-
<span className="tags"> {h} </span>
114-
) : null;
115-
})}
115+
{hobbies.length > 0 ? hobbies.map(h => {console.log({h}); return <span id='hobbyTag' className="tags"> {h}</span>}
116+
): null}
116117
</div>
117-
118118
<div className="form-row">
119119
<div className="form-group col-md-6">
120120
<label for="exampleFormControlSelect2">Skills</label>
@@ -136,7 +136,7 @@ const EditProfile = (props) => {
136136
<div className="form-group">
137137
{skills.map((s) => {
138138
return skills.length >= 1 ? (
139-
<span className="tags"> {s} </span>
139+
<span id='skillTag' className="tags"> {s} </span>
140140
) : null;
141141
})}
142142
</div>

src/styles/editProfile.sass

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
$padding: 10px
2+
$primary-color: #FFF
3+
4+
#hobbyTag
5+
color: $primary-color
6+
7+

0 commit comments

Comments
 (0)