-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from gamandeepsingh/main
hiring Partner- EasyEd added and Mobile number changed
- Loading branch information
Showing
6 changed files
with
224 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,54 @@ | ||
|
||
import './Counter.css' | ||
import "./Counter.css"; | ||
import { FcLike } from "react-icons/fc"; | ||
import { useState, useEffect } from 'react'; | ||
import { useState, useEffect } from "react"; | ||
// import 'firebase/database'; | ||
import { initializeApp } from "firebase/app"; | ||
import { getDatabase, ref, set } from 'firebase/database'; | ||
import { onValue } from 'firebase/database'; | ||
import { getDatabase, ref, set } from "firebase/database"; | ||
import { onValue } from "firebase/database"; | ||
|
||
const firebaseConfig = { | ||
apiKey: "AIzaSyB8JNy6K7F-FleyUxq4BmfCO0mIGqnvEfs", | ||
authDomain: "innohacks-like-counter.firebaseapp.com", | ||
databaseURL: "https://innohacks-like-counter-default-rtdb.asia-southeast1.firebasedatabase.app", | ||
projectId: "innohacks-like-counter", | ||
storageBucket: "innohacks-like-counter.appspot.com", | ||
messagingSenderId: "227514540661", | ||
appId: "1:227514540661:web:4736b67774954f5f580e3c" | ||
}; | ||
apiKey: "AIzaSyB8JNy6K7F-FleyUxq4BmfCO0mIGqnvEfs", | ||
authDomain: "innohacks-like-counter.firebaseapp.com", | ||
databaseURL: | ||
"https://innohacks-like-counter-default-rtdb.asia-southeast1.firebasedatabase.app", | ||
projectId: "innohacks-like-counter", | ||
storageBucket: "innohacks-like-counter.appspot.com", | ||
messagingSenderId: "227514540661", | ||
appId: "1:227514540661:web:4736b67774954f5f580e3c", | ||
}; | ||
const app = initializeApp(firebaseConfig); | ||
const database = getDatabase(app); | ||
const countRef = ref(database, 'count'); | ||
|
||
|
||
const countRef = ref(database, "count"); | ||
|
||
const Counter = () => { | ||
const [count, setCount] = useState(0); | ||
useEffect(() => { | ||
const unsubscribe = onValue(countRef, (snapshot) => { | ||
setCount(snapshot.val() || 0); | ||
}); | ||
return () => unsubscribe(); | ||
}, []); | ||
const handleClick = () => { | ||
// Increment count | ||
const newCount = count + 1; | ||
|
||
// Update count in Firebase Realtime Database | ||
set(countRef, newCount) | ||
.then(() => { | ||
setCount(newCount); | ||
}) | ||
.catch(error => { | ||
console.error('Error updating count in Firebase:', error); | ||
}); | ||
const [count, setCount] = useState(0); | ||
useEffect(() => { | ||
const unsubscribe = onValue(countRef, (snapshot) => { | ||
setCount(snapshot.val() || 0); | ||
}); | ||
return () => { | ||
unsubscribe(); | ||
}; | ||
}, []); | ||
const handleClick = () => { | ||
// Increment count | ||
const newCount = count + 1; | ||
|
||
// Update count in Firebase Realtime Database | ||
set(countRef, newCount) | ||
.then(() => { | ||
setCount(newCount); | ||
}) | ||
.catch((error) => { | ||
console.error("Error updating count in Firebase:", error); | ||
}); | ||
}; | ||
|
||
return ( | ||
<button id="hitCounter" onClick={handleClick}> | ||
<FcLike/> {count} | ||
</button> | ||
); | ||
return ( | ||
<button id="hitCounter" onClick={handleClick}> | ||
<FcLike /> {count} | ||
</button> | ||
); | ||
}; | ||
|
||
export default Counter; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.