what is the best book for learn react js ?
hello guy’s i am going to learn react js.
so that’s why i need a book to learn react.
now can u guy’s suggest me a good book to learn react???
Blancer.com Tutorials and projects
Freelance Projects, Design and Programming Tutorials
Category Added in a WPeMatico Campaign
hello guy’s i am going to learn react js.
so that’s why i need a book to learn react.
now can u guy’s suggest me a good book to learn react???
I am using selectareas.js to select some parts of the image with mouse event and getting coordinates x,y,z of the image, as I am selecting multiple areas of the image, all the values are printing/console in my browser correctly.
Now I am trying to Show all those selected coordinates of image areas as a new image in a different canvas/div on a button click event.
So technically when I am selecting 2,3 or 4 areas all coordinates values prints like this in an array
0: {id: 0, x: 10, y: 20, z: 0, height: 100,width: 60}
1: {id: 1, x: 159.5, y: 286, z: 0, height: 73,width: 220}
2: {id: 2, x: 464.5, y: 300, z: 100, height: 117,width: 221}
Now I am trying to figure out how to show these coordinates as a different new image on my
page or downloads all as a new image by converting into base64.
HTML-
<div class="image-decorator">
<img alt="Image principale" id="example" src="example.jpg" />
</div>
<table>
<tr>
<td class="actions">
<input type="button" id="btnView" value="Display areas" class="actionOn" />
<td>
<div id="output" class='output'> </div>
</td>
</tr>
</table>
</div>
JQUERY:
$(document).ready(function () {
$('img#example').selectAreas({
minSize: [10, 10],
onChanged: debugQtyAreas,
width: 1000
});
$('#btnView').click(function () {
var areas = $('img#example').selectAreas('areas');
displayAreas(areas);
});
});
Was following a tutorial and my localhost is completely blank after importing {Link} from react-router-dom. Followed word for word but my local host is blank as soon as I added link in navbar.js. Please help.
import React from 'react';
import {Link} from 'react-router-dom';
function Navbar() {
return(
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<Link to="/" class="navbar-brand">SkyCloud</Link>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-togglser-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<Link to="/" class="nav-link active">Home</Link>
</li>
<li class="nav-item">
<Link to="/about" class="nav-link active">About</Link>
</li>
<li class="nav-item">
<Link to="/contact" class="nav-link active">Contact</Link>
</li>
</ul>
</div>
</div>
</nav>
);
}
export default Navbar;
And this is my App.js file…
import React from 'react';
import Navbar from './components/inc/Navbar';
import Home from './components/pages/Home';
import About from './components/pages/About';
import Contact from './components/pages/Contact';
import {BrowserRouter as Router} from 'react-router-dom';
function App() {
return (
<Router>
<div>
<Navbar/>
<Home/>
<About/>
<Contact/>
</div>
</Router>
);
}
export default App;
Please help(this is my first question btw).
I am trying to generate a input value based on 2 earlier input values the user filled in. First is a name, the second one is a date. Now I need to concat and format these 2 values and set them for another input.
This is what I already come up with:
The code I have so far:
window.onload = function () {
/* event listener for first input: Name */
document.getElementById('input_7_1').addEventListener('change', formatTitle);
/* function to format the name value properly */
function formatTitle(){
document.getElementById('input_7_1').addEventListener("input", function(){
var title = document.getElementById('input_7_1').value;
var formatTitle = title.replace(/s+/g, '');
});
}
/* event listener for second input: Date */
document.getElementById('input_7_3').addEventListener('change', formatDate);
/* function to format the date value properly */
function formatDate(){
document.getElementById('input_7_3').addEventListener("input", function(){
var date = document.getElementById('input_7_3').value.replace(///g, '');
var formatDate = date.slice(0, -4);
});
}
/* concat both values in a variable */
var studentNummer = formatTitle.concat(formatDate);
/* set value in the third input: Studentnummer */
function generateInput(){
document.getElementById('input_7_9').value = studentNummer;
}
}
I am almost there for my feeling. What am I missing here?
I’m looking how to trigger onChange function when an option is already selected and clicked by the user to deselect it, it’s like multiselect.
you can select an option and deselect it by clicking on it a second time.
this is what i’ve already tried.
everything is working when there is more than 1 option selected, but not when there is only one option selected.
const handleChangeGroup = (selectedItems) => {
const groups = [];
for (let i = 0; i < selectedItems.length; i++) {
if (groupArray.includes(selectedItems[i].value)) {
if (groupArray.length === 0) {
setGroupArray([]);
} else {
var newArray = groupArray.filter(
(value) => value != selectedItems[i].value
);
setGroupArray(newArray);
}
} else {
groups.push(selectedItems[i].value);
setGroupArray(groupArray.concat(groups));
}
}
};
<select
multiple={true}
value={groupArray}
onChange={(event) =>
handleChangeGroup(event.target.selectedOptions)
}>
{data[selectType] !== undefined
? Object.keys(data[selectType]).map((group, index) => (
<option value={group} key={group}>
{group}
</option>
))
: null}
</select>
Uncaught TypeError: $(…).slicknav is not a function
I’ve downloaded free html template and it works correctly when i open it without Laravel, but when i compile CSS and JS with Laravel Mix one of the JS libraries stops working. The error looks like i didn’t plug it in html, but everything is ok and other libraries work correctly. I also tried npm install slicknav and include it in webpack.mix.js‘s autoload, rebuild after that but nothing changes.
bottom of index.blade.php:
<script src="{{mix('js/jquery-3.3.1.min.js')}}"></script>
<script src="{{mix('js/bootstrap.min.js')}}"></script>
<script src="{{mix('js/jquery.nice-select.min.js')}}"></script>
<script src="{{mix('js/jquery-ui.min.js')}}"></script>
<script src="{{mix('js/jquery.slicknav.js')}}"></script>
<script src="{{mix('js/mixitup.min.js')}}"></script>
<script src="{{mix('js/owl.carousel.min.js')}}"></script>
<script src="{{mix('js/main.js')}}"></script>
webpack.mix.js:
mix.js('resources/js/app.js', 'public/js')
.js('resources/js/jquery-3.3.1.min.js', 'public/js')
.js('resources/js/bootstrap.min.js', 'public/js')
.js('resources/js/jquery.nice-select.min.js', 'public/js')
.js('resources/js/jquery-ui.min.js', 'public/js')
.js('resources/js/jquery.slicknav.js', 'public/js')
.js('resources/js/mixitup.min.js', 'public/js')
.js('resources/js/owl.carousel.min.js', 'public/js')
.js('resources/js/main.js', 'public/js')
.css('resources/css/bootstrap.min.css', 'public/css')
.css('resources/css/font-awesome.min.css', 'public/css')
.css('resources/css/elegant-icons.css', 'public/css')
.css('resources/css/nice-select.css', 'public/css')
.css('resources/css/jquery-ui.min.css', 'public/css')
.css('resources/css/owl.carousel.min.css', 'public/css')
.css('resources/css/slicknav.min.css', 'public/css')
.css('resources/css/style.css', 'public/css')
.postCss('resources/css/app.css', 'public/css')
.autoload({
jquery: ['$', 'window.jQuery', 'jQuery'],
mixitup: ['mixitup']
})
.sourceMaps()
The error in chrome console:
https://i.stack.imgur.com/WnHCI.png
I was building UI for a dictionary which shows a word followed by its meaning. In the below code I’m setting up the setInterval initially and then on some events. I’m just focused on initial setInterval.
Although I’m quite experienced in React but I am still not able to grab my head around why the setInterval works when inside useEffect hook but not from the if condition.
To replicate just comment out the if condition and uncomment useEffect block.
Can someone please explain?
import React, { useState, useEffect } from 'react';
import Dictionary from './Dictionary.json';
import './App.css';
const words = Object.keys(Dictionary);
let currentInterval;
function App() {
const [randomWord, setRandomWord] = useState(words && words[Math.round(Math.random() * words.length)]);
const [wordGenerationDuration, setWordGenerationDuration] = useState(10000);
function selectRandomWord() {
setRandomWord(words[Math.round(Math.random() * (words.length - 1))]);
}
if(!currentInterval) {
currentInterval = setInterval(selectRandomWord, wordGenerationDuration);
}
// useEffect(
// () => {
// currentInterval = setInterval(selectRandomWord, wordGenerationDuration);
// }, []
// )
return (
<div className='App'>
<div className='dictionary-wrapper'>
<p className='dictionary-word'>
{randomWord}
</p>
<p className='dictionary-meaning'>
{Dictionary[randomWord]}
</p>
<p className='next-button cursor-pointer'>
<span
onClick={
() => {
clearInterval(currentInterval);
selectRandomWord();
currentInterval = setInterval(selectRandomWord, wordGenerationDuration);
}
}
>
Next Word
</span>
</p>
<p>
<span>Auto Switch Duration:</span>
<input
className='dictionary-input'
type='number'
placeholder={wordGenerationDuration / 1000}
onChange={
(evt) => {
const wordGenerationDuration = Math.max(evt.target?.value * 1000, 10000);
clearInterval(currentInterval);
setWordGenerationDuration(wordGenerationDuration);
currentInterval = setInterval(selectRandomWord, wordGenerationDuration);
}
}
min='10'
/>
</p>
</div>
</div>
);
}
export default App;
I am working on a Rust WASM library that works with the DOM. To simplify matters, let’s assume that this library receives a Node as argument, determines its root node and appends a newly created div to that root node (Link to repo with complete MRE including HTML/JS):
#[wasm_bindgen]
pub fn append_div_to_document_containing(element: web_sys::HtmlElement) {
console_error_panic_hook::set_once();
let document = element
.get_root_node()
.dyn_into::<web_sys::HtmlDocument>()
.expect("get_root_node() did not return Document");
let div = document
.create_element("div")
.expect("create_element() failed");
div.set_text_content(Some("Created by WASM"));
document
.body()
.expect("root_node.body() returned null")
.append_with_node_1(&div)
.expect("Appending failed");
}
Additionally, I have created JavaScript that can run this function on either a div contained in the current window or a div contained in a new window created via window.open:
<input type="button" id="div_here" value="Add div here">
<input type="button" id="div_window_open" value="Add div via window.open()">
<script type="module">
import init, { append_div_to_document_containing } from './pkg/window_open_chrome_instanceof.js';
window.onload = () => {
async function run() {
await init();
function createDivsWithJsAndWasm(document) {
let div = document.createElement("div");
div.textContent = "Created by JS";
document.body.append(div);
append_div_to_document_containing(div);
}
document.querySelector("#div_here").addEventListener("click", () => {
createDivsWithJsAndWasm(document);
});
document.querySelector("#div_window_open").addEventListener("click", () => {
createDivsWithJsAndWasm(window.open("", "", "popup").document);
});
}
run();
};
</script>
Both cases work in Firefox. However, the window.open() case fails in Chrome:
window_open_chrome_instanceof.js:260 panicked at 'get_root_node() did not return Document: Node { obj: EventTarget { obj: Object { obj: JsValue(HTMLDocument) } } }', src/lib.rs:11:10
Stack:
Error
at http://192.168.12.34:8000/pkg/window_open_chrome_instanceof.js:266:19
at logError (http://192.168.12.34:8000/pkg/window_open_chrome_instanceof.js:189:18)
at imports.wbg.__wbg_new_693216e109162396 (http://192.168.12.34:8000/pkg/window_open_chrome_instanceof.js:265:66)
at console_error_panic_hook::Error::new::h04dcf1f78b1b65a5 (http://192.168.12.34:8000/pkg/window_open_chrome_instanceof_bg.wasm:wasm-function[433]:0x1577b)
at console_error_panic_hook::hook_impl::haf0cbfc93cb83b73 (http://192.168.12.34:8000/pkg/window_open_chrome_instanceof_bg.wasm:wasm-function[43]:0x6e7a)
at console_error_panic_hook::hook::hff46bfaa806ee83e (http://192.168.12.34:8000/pkg/window_open_chrome_instanceof_bg.wasm:wasm-function[483]:0x162ad)
at core::ops::function::Fn::call::hd9fb438233d248fe (http://192.168.12.34:8000/pkg/window_open_chrome_instanceof_bg.wasm:wasm-function[406]:0x150dc)
at std::panicking::rust_panic_with_hook::hf4c39fada27bd187 (http://192.168.12.34:8000/pkg/window_open_chrome_instanceof_bg.wasm:wasm-function[116]:0xc839)
at std::panicking::begin_panic_handler::{{closure}}::he7338bd7a89ffcbb (http://192.168.12.34:8000/pkg/window_open_chrome_instanceof_bg.wasm:wasm-function[186]:0xfc2b)
at std::sys_common::backtrace::__rust_end_short_backtrace::h0ded0f05f9eb8d88 (http://192.168.12.34:8000/pkg/window_open_chrome_instanceof_bg.wasm:wasm-function[612]:0x175c5)
I assume this is because in Chrome, the document contained in the opened window is not instanceof HTMLDocument, but instanceof new_window.HTMLDocument:
let new_window = window.open("", "", "popup")
console.log(new_window.document instanceof HTMLDocument); // false in Chrome, true in Firefox
console.log(new_window.document instanceof new_window.HTMLDocument); // true in Chrome, true in Firefox
This isn’t just a problem with the document object, but with every JavaScript object that is associated with the new window. For example, the CanvasRenderingContext2D of a canvas inside the new window is not instanceof CanvasRenderingContext2D, but instanceof new_window.CanvasRenderingContext2D. Even the window itself is not instanceof Window, but instanceof new_window.Window:
let new_window = window.open("", "", "popup")
console.log(new_window instanceof Window); // false in Chrome, true in Firefox
console.log(new_window instanceof new_window.Window); // true in Chrome, true in Firefox
An easy solution in this example would be to use unchecked_into() instead of dyn_into(). However, in my real code, there are multiple dyn_into() invocations that I would need to replace with unchecked_into(), and I don’t like the idea of giving up type safety just for this edge case.
Is there any workaround that allows successful dyn_into() casts on JavaScript objects that are part of a window created via window.open?
I have a build.js file which, as you may have guessed, builds my project. This file aims to:
.ts files and place them into a new directory.Because typescript (tsc) is an NPM package, I figured I might be able to use it inside of a JavaScript file, in the same way I can use the asar package. I was right; I can use the typescript package as a regular Node.JS module, however, I do not know how to use it, and ESLint doesn’t help me out too much.
Here’s my current build.js:
const typescript = require("typescript");
I cannot find any documentation for this, all I want to do is replicate what tsc . would do.
It might be cheating but is their a way to add time using a game that was built with JavaScript. It’s just simple word search game. But I want to know if theirs a way to use a function that updates the timer in the browser’s console? If people are curious then let me know to show the function code
I’m trying to make a component that updates its source image on scroll when it gets referenced in its div tag ‘ infoBG ‘in my main component. The function seems to work but I guess the return statement is overriding the function and just returns the original image without updating. What’s the right way to do this so the function updates the first returned image?
function Infoimg () {
window.addEventListener("scroll", event => {
var scrollValue = window.scrollY;
var image = document.getElementById('infoBG');
if (scrollValue>100){
image.setAttribute = ('src','images/ccpLogo.svg');
}else{
image.setAttribute = ('src','images/Passport Stock Photo.svg');
}
console.log(image)
console.log(scrollValue);
});
return(
<img src={'images/Passport Stock Photo.svg'} alt='Info-Background'/>
)
}
I am working on a backend with Nodejs that uses a sendgrid inbound parse webhook to retrieve emails sent to my domain. I have everything set up and it works as it should. I can send emails to my domain and process them with the webhook. My problem is that if I send an email with an attachment larger than 500kb, the webhook does not process that email (does not retrieve it). I looked in the documentation, but I didn’t find any information about the maximum size of attachments for the inbound parse (I found information about the API for sending emails, but not for retrieving them). Is there a limit for attachments for inbound parse? (I use the free version)
{
“manifest_version”: 3 ,
“version” : “1.01” ,
“name” : “Traker” ,
“action”:{
“default_popup” : “index.html” ,
“default_icon” :”icon.png”
},
“permissions”: [
“tabs”
] ,
“content_security_policy”: “script-src ‘self’ https://ajax.googleapis.com; object-src ‘self'”
}
Hi I am currently working on an app that’s setting items in localStorage then later retrieve all items. When retrieving I am parsing the object to convert it from a stringified object to an object. On doing that I am getting this error,
Error: A cross-origin error was thrown. React doesn’t have access to the actual error object in development.
I tried to look for solutions but the one that’s suggested is to clear local storage but It’s a problem because I’ll have to do that each time I press my button. Is there a fix for this.
My code:
// This function gets all items from the local storage
function getAll() {
var values = [],
keys = Object.keys(localStorage),
i = keys.length;
while (i--) {
values.push(localStorage.getItem(keys[i]));
}
return values;
}
const getMissions = getAll();
// This variable stores the parsed value, ie, turning a stringified object back to an object value
const { image, missionName } = JSON.parse(getMissions);
Thank you in advance
Am new to loopback 4, I want to get the user IP address, their domain details, the url they are trying to access so on so i wrote a sequence, i have accessed the request context but couldn’t get the exact key to find out the details am looking for
export class MySequence extends MiddlewareSequence {
async handle(context: RequestContext): Promise<void> {
const {request, response} = context;
console.log('Isnide', {request});
const data = await super.handle(context);
}
}