React Fragments With Examples
KnpCode
by UshaK
2y ago
In this tutorial we’ll see what is React.Fragment and how to use it. Table of contents Why React Fragment React Fragment Usage Fragment short syntax Key with Fragments Why React Fragment When you write a React component there is a constraint that the JSX expression the component will render should always be wrapped with in a single parent element. Which means trying to write a component as given below results in an error. const HelloWorld = (props) => { return ( <h2>{props.title}</h2> <p>{props.message.greeting} {props.message.name}</p> ..read more
Visit website
React useState Hook With Examples
KnpCode
by UshaK
2y ago
The React useState hook is used to add state to your functional component. That way you can track the state in a component. Table of contents What does useState hook do React useState hook example Change state using previous state Using useState with forms Form example with multiple state hooks Form example with Single state hook What does useState hook do When we say useState tracks the state in a functional component it means it can track the changes in the data in your component which may be any variable, object in the component. Any change in the data can be termed as the state chan ..read more
Visit website
Java Stream Collectors.collectingAndThen() Examples
KnpCode
by UshaK
2y ago
In this tutorial you’ll see how to use Collectors.collectingAndThen() method with the help of some examples. Collectors.collectingAndThen() method in Java Stream As the name of the method itself suggests this method helps you to provide logic for two steps in a single method call. 1. How to collect stream elements. 2. What to do after collecting Stream elements. Syntax of collectingAndThen() method is as given below- Collector<T,A,RR> collectingAndThen(Collector<T,A,R> downstream, Function<R,RR> finisher) Here parameters are- downstream– A collector that is applied to stream ..read more
Visit website
React Props With Examples
KnpCode
by UshaK
2y ago
In this tutorial you’ll learn how to use props on React components. Table of contents Why do we need props React props example Passing more than one value as props Passing down data using props Why do we need props When you create a component in React you want it to be reusable, which involves calling the same component with different values just like methods where you can pass parameters. In simple terms ‘props’ are the arguments passed to the user-defined component. When you use your component as an element you can pass values to it as attributes. When React sees an element representing ..read more
Visit website
React App Flow – create-react-app Structure
KnpCode
by UshaK
2y ago
If you are starting to learn Reactjs and just created your first Hello World React app, you may be wondering what is the flow of the React app. Moreover, if you have used create-react-app to set up your project structure, you get a readymade default app and if you execute command npm start you can also view the application by going to URL- http://localhost:3000. Again, if you are wondering how you got this display and what all happened underneath to get to this display on your browser then this article will help you in understanding the React app flow. React project structure (create-react-ap ..read more
Visit website
Wrapper Class in Java
KnpCode
by UshaK
2y ago
Wrapper class in Java is a class whose object wraps a primitive type. When you need an object instead of a primitive type you can use Wrapper class to wrap the primitive type value in an object and use that object. Wrapper classes in Java for primitive types For all eight primitive data types there is a corresponding Wrapper class in Java. Primitive Type Wrapper class boolean Boolean char Character byte Byte short Short int Integer long Long float Float double Double Out of these 8 wrapper classes 6 are numeric. All of the numeric wrapper classes are subclasses of the abs ..read more
Visit website
Installing Node.js and NPM on Windows
KnpCode
by UshaK
2y ago
Node.js is a popular run time environment for executing JavaScript applications. If you are using popular JS frameworks like Angular, React then also it is required that you should have Node.js installed on your system. In this tutorial we’ll see how to download and install Node.js and NPM (Node Package Manager) on a Windows system. Installing Node.js and NPM on windows 1. Downloading Node.js installer You can download Node.js from this location- https://nodejs.org/en/download/ Once you are on the page select one of the two choices LTS or Current. Better to opt for LTS (Long Term Support) vers ..read more
Visit website
First React App – Hello World React Example
KnpCode
by UshaK
2y ago
In this tutorial you will see how to write your first React program, a Hello World React application that gets you started with creating a Reactjs project and then writing code to display Hello World in a browser. Table of contents Create React App for Creating Reactjs project Creating HelloWorld React application Creating React component React component as ES6 class Create React App for Creating Reactjs project create-react-app command provides an easy way to create a Reactjs project with default configuration. You don’t need to install or configure tools like webpack or Babel yourself se ..read more
Visit website
Java Stream Collectors summingInt(), summingLong(), summingDouble()
KnpCode
by UshaK
2y ago
In the tutorial Java Stream Collectors averagingInt(), averagingLong(), averagingDouble() we saw how Collectors class in Java Stream API provides methods like Collectors.averagingInt(), Collectors.averagingLong(), Collectors.averagingDouble() to get average of Stream on Integers, Long and Double respectively. Same way if you want to quickly add the stream elements there are Collectors.summing() methods which have the following forms for different types- summingInt(ToIntFunction<? super T> mapper)– To get sum of stream of integers. If no elements are present, the result is 0. summingLong ..read more
Visit website
Java Stream Collectors averagingInt(), averagingLong(), averagingDouble()
KnpCode
by UshaK
2y ago
If you want average of Stream elements there are handy utility methods available in Collectors class to quickly do that, the methods are- Collectors.averagingInt()- To get average of stream of integers. Collectors.averagingLong()- To get average of stream of longs. Collectors.averagingDouble()- To get average of stream of doubles. Collectors.averaging methods in Java Syntax of these methods is as given below- Collector<T,?,Double> averagingInt(ToIntFunction<? super T> mapper) Collector<T,?,Double> averagingLong(ToLongFunction<? super T> mapper) Collector<T,?,Dou ..read more
Visit website

Follow KnpCode on FeedSpot

Continue with Google
Continue with Apple
OR